﻿using CMK.K3.RI.STORE.Contract;
using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Log;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.WebApi.Client;
using KingdeeWebServiceProject.Utils;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Kingdee.BOS.WebApi.FormService;

namespace KingdeeWebServiceProject
{
    internal class CMKRetailService
    {

        internal string CreateGoods(Context ctx, string strParams, JObject result)
        {
            JObject jParams = JObject.Parse(strParams);
            string dataCenterID = CommonService.GetJParamString(jParams, "dataCenterID");
            string userName = CommonService.GetJParamString(jParams, "userName");
            string passWord = CommonService.GetJParamString(jParams, "passWord");
            string OrgNumber = CommonService.GetJParamString(jParams, "FCreateOrgId");
            string UseOrgNumber = CommonService.GetJParamString(jParams, "FUseOrgId");
            List<SqlParam> lstParam = new List<SqlParam>();
            if (string.IsNullOrWhiteSpace(OrgNumber))
            {
                result["Result"] = false;
                result["Message"] = "创建组织编码不能为空！";
                return result.ToString();
            }
            if (string.IsNullOrWhiteSpace(UseOrgNumber))
            {
                result["Result"] = false;
                result["Message"] = "使用组织编码不能为空！";
                return result.ToString();
            }
            string OrgId = CommonService.VKGetBaseDataIdByValue(ctx, OrgNumber);
            if (OrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FCreateOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string UseOrgId = CommonService.VKGetBaseDataIdByValue(ctx, UseOrgNumber);
            if (OrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FUseOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string GoodsNumber = CommonService.GetJParamString(jParams, "FNumber");
            if (string.IsNullOrWhiteSpace(GoodsNumber))
            {
                result["Result"] = false;
                result["Message"] = "商品编码不能为空！";
                return result.ToString();
            }
            string GoodsName = CommonService.GetJParamString(jParams, "FName");
            if (string.IsNullOrWhiteSpace(GoodsName))
            {
                result["Result"] = false;
                result["Message"] = "商品名称不能为空！";
                return result.ToString();
            }
            string FTHIRDSRCTYPE = CommonService.GetJParamString(jParams, "FTHIRDSRCTYPE");
            string FTHIRDBILLID = CommonService.GetJParamString(jParams, "FTHIRDBILLID");
            string FTHIRDBILLNO = CommonService.GetJParamString(jParams, "FTHIRDBILLNO");
            string FMnemonicCode = CommonService.GetJParamString(jParams, "FMnemonicCode");
            string FSpecification = CommonService.GetJParamString(jParams, "FSpecification");
            string FOldNumber = CommonService.GetJParamString(jParams, "FOldNumber");
            try
            {
                string metail = "{\"NeedUpDateFields\":[],\"NeedReturnFields\":[],\"IsDeleteEntry\":\"true\",\"SubSystemId\":\"\",\"IsVerifyBaseDataField\":\"false\",\"IsEntryBatchFill\":\"true\",\"ValidateFlag\":\"true\",\"NumberSearch\":\"true\",\"IsAutoAdjustField\":\"false\",\"InterationFlags\":\"\",\"IgnoreInterationFlag\":\"\",\"Model\":{\"FMATERIALID\":0,\"FCreateOrgId\":{\"FNumber\":\"创建组织编码\"},\"FUseOrgId\":{\"FNumber\":\"组织编码\"},\"FNumber\":\"商品编码\",\"FName\":\"商品名称\",\"FSpecification\":\"规格型号\",\"FMnemonicCode\":\"助记码\",\"FOldNumber\":\"旧物料编码\",\"FDSMatchByLot\":false,\"FImgStorageType\":\"B\",\"FIsSalseByNet\":false,\"FTHIRDSRCTYPE\":\"第三方来源\",\"FTHIRDBILLID\":\"第三方单据ID\",\"FTHIRDBILLNO\":\"第三方单据编号\",\"FSubHeadEntity\":{\"FIsControlSal\":false,\"FIsAutoRemove\":false,\"FIsMailVirtual\":false,\"FIsPrinttAg\":false,\"FIsAccessory\":false},\"SubHeadEntity\":{\"FErpClsID\":\"1\",\"FFeatureItem\":\"1\",\"FCategoryID\":{\"FNumber\":\"CHLB01_SYS\"},\"FTaxType\":{\"FNumber\":\"WLDSFL01_SYS\"},\"FTaxRateId\":{\"FNUMBER\":\"SL02_SYS\"},\"FBaseUnitId\":{\"FNumber\":\"tai\"},\"FIsPurchase\":true,\"FIsInventory\":true,\"FIsSubContract\":false,\"FIsSale\":true,\"FIsProduce\":false,\"FIsAsset\":false,\"FWEIGHTUNITID\":{\"FNUMBER\":\"kg\"},\"FVOLUMEUNITID\":{\"FNUMBER\":\"m\"}},\"SubHeadEntity1\":{\"FStoreUnitID\":{\"FNumber\":\"tai\"},\"FUnitConvertDir\":\"1\",\"FIsLockStock\":true,\"FIsCycleCounting\":false,\"FCountCycle\":\"1\",\"FCountDay\":1,\"FIsMustCounting\":false,\"FIsBatchManage\":false,\"FIsKFPeriod\":false,\"FIsExpParToFlot\":false,\"FCurrencyId\":{\"FNumber\":\"PRE001\"},\"FIsEnableMinStock\":false,\"FIsEnableMaxStock\":false,\"FIsEnableSafeStock\":false,\"FIsEnableReOrder\":false,\"FIsSNManage\":false,\"FIsSNPRDTracy\":false,\"FSNManageType\":\"1\",\"FSNGenerateTime\":\"1\"},\"SubHeadEntity2\":{\"FSaleUnitId\":{\"FNumber\":\"tai\"},\"FSalePriceUnitId\":{\"FNumber\":\"tai\"},\"FMaxQty\":100000.0,\"FIsATPCheck\":false,\"FIsReturnPart\":false,\"FIsInvoice\":false,\"FIsReturn\":true,\"FAllowPublish\":false,\"FISAFTERSALE\":true,\"FISPRODUCTFILES\":true,\"FISWARRANTED\":false,\"FWARRANTYUNITID\":\"D\",\"FOutLmtUnit\":\"SAL\",\"FIsTaxEnjoy\":false,\"FUnValidateExpQty\":false},\"SubHeadEntity3\":{\"FPurchaseUnitId\":{\"FNumber\":\"tai\"},\"FPurchasePriceUnitId\":{\"FNumber\":\"tai\"},\"FIsQuota\":false,\"FQuotaType\":\"1\",\"FIsVmiBusiness\":false,\"FEnableSL\":false,\"FIsPR\":false,\"FIsReturnMaterial\":true,\"FIsSourceControl\":false,\"FPOBillTypeId\":{\"FNUMBER\":\"CGSQD01_SYS\"},\"FPrintCount\":1},\"SubHeadEntity4\":{\"FPlanningStrategy\":\"1\",\"FMfgPolicyId\":{\"FNumber\":\"ZZCL001_SYS\"},\"FFixLeadTimeType\":\"1\",\"FVarLeadTimeType\":\"1\",\"FCheckLeadTimeType\":\"1\",\"FOrderIntervalTimeType\":\"3\",\"FMaxPOQty\":100000.0,\"FEOQ\":1.0,\"FVarLeadTimeLotSize\":1.0,\"FIsMrpComBill\":true,\"FIsMrpComReq\":false,\"FReserveType\":\"1\",\"FAllowPartAhead\":false,\"FCanDelayDays\":999,\"FAllowPartDelay\":true,\"FPlanOffsetTimeType\":\"1\",\"FWriteOffQty\":1.0},\"SubHeadEntity5\":{\"FProduceUnitId\":{\"FNumber\":\"tai\"},\"FProduceBillType\":{\"FNUMBER\":\"SCDD03_SYS\"},\"FOrgTrustBillType\":{\"FNUMBER\":\"SCDD06_SYS\"},\"FIsSNCarryToParent\":false,\"FIsProductLine\":false,\"FBOMUnitId\":{\"FNumber\":\"tai\"},\"FIsMainPrd\":false,\"FIsCoby\":false,\"FIsECN\":false,\"FIssueType\":\"1\",\"FOverControlMode\":\"1\",\"FMinIssueQty\":1.0,\"FISMinIssueQty\":false,\"FIsKitting\":false,\"FIsCompleteSet\":false,\"FMinIssueUnitId\":{\"FNUMBER\":\"tai\"},\"FStandHourUnitId\":\"3600\",\"FBackFlushType\":\"1\"},\"SubHeadEntity7\":{\"FSubconUnitId\":{\"FNumber\":\"tai\"},\"FSubconPriceUnitId\":{\"FNumber\":\"tai\"},\"FSubBillType\":{\"FNUMBER\":\"WWDD01_SYS\"}},\"SubHeadEntity6\":{\"FCheckIncoming\":false,\"FCheckProduct\":false,\"FCheckStock\":false,\"FCheckReturn\":false,\"FCheckDelivery\":false,\"FEnableCyclistQCSTK\":false,\"FEnableCyclistQCSTKEW\":false,\"FCheckEntrusted\":false,\"FCheckOther\":false,\"FIsFirstInspect\":false,\"FCheckReturnMtrl\":false},\"FEntityInvPty\":[{\"FInvPtyId\":{\"FNumber\":\"01\"},\"FIsEnable\":true,\"FIsAffectPrice\":false,\"FIsAffectPlan\":false,\"FIsAffectCost\":false},{\"FInvPtyId\":{\"FNumber\":\"02\"},\"FIsEnable\":true,\"FIsAffectPrice\":false,\"FIsAffectPlan\":false,\"FIsAffectCost\":false},{\"FInvPtyId\":{\"FNumber\":\"03\"},\"FIsEnable\":false,\"FIsAffectPrice\":false,\"FIsAffectPlan\":false,\"FIsAffectCost\":false},{\"FInvPtyId\":{\"FNumber\":\"04\"},\"FIsEnable\":false,\"FIsAffectPrice\":false,\"FIsAffectPlan\":false,\"FIsAffectCost\":false},{\"FInvPtyId\":{\"FNumber\":\"06\"},\"FIsEnable\":false,\"FIsAffectPrice\":false,\"FIsAffectPlan\":false,\"FIsAffectCost\":false}]}}";
                metail = metail.Replace("创建组织编码", OrgId);
                metail = metail.Replace("组织编码", UseOrgId);
                metail = metail.Replace("商品编码", GoodsNumber);
                metail = metail.Replace("商品名称", GoodsName);
                metail = metail.Replace("助记码", FMnemonicCode);
                metail = metail.Replace("规格型号", FSpecification);
                metail = metail.Replace("旧物料编码：", FOldNumber);
                metail = metail.Replace("第三方来源", FTHIRDSRCTYPE);
                metail = metail.Replace("第三方单据ID", FTHIRDBILLID);
                metail = metail.Replace("第三方单据编号", FTHIRDBILLNO);

                object saveres = WebApiServiceCall.Save(ctx, "BD_MATERIAL", metail);
                JObject res = JObject.FromObject(saveres);
                JObject res1 = JObject.Parse(res["Result"].ToString());
                JObject res2 = JObject.Parse(res1["ResponseStatus"].ToString());
                if (!res2["SuccessEntitys"].ToString().Equals("[]"))
                {
                    JArray content = JArray.Parse(res2["SuccessEntitys"].ToString());
                    foreach (JObject List in content)
                    {
                        string fnumber = List["Number"].ToString();
                        string Submit = "{\"Numbers\":[\"编码\"]}";
                        Submit = Submit.Replace("编码", fnumber);
                        object sub = WebApiServiceCall.Submit(ctx, "BD_MATERIAL", Submit);
                        JObject st1 = JObject.FromObject(sub);
                        JObject st2 = JObject.Parse(st1["Result"].ToString());
                        JObject st3 = JObject.Parse(st2["ResponseStatus"].ToString());
                        object aud =  WebApiServiceCall.Audit(ctx, "BD_MATERIAL", Submit);
                        JObject st4 = JObject.FromObject(aud);
                        JObject st5 = JObject.Parse(st4["Result"].ToString());
                        JObject st6 = JObject.Parse(st5["ResponseStatus"].ToString());

                    }
                }
                result["Result"] = true;
                result["Message"] = res["Result"].ToString();
            }
            catch (Exception e)
            {
                result["Result"] = false;
                result["Message"] = "数据格式不正确！" + e.Message;
            }
            return result.ToString();
        }

        internal string Customer(Context ctx, string strParams, JObject result)
        {
            JObject jParams = JObject.Parse(strParams);
            string dataCenterID = CommonService.GetJParamString(jParams, "dataCenterID");
            string userName = CommonService.GetJParamString(jParams, "userName");
            string passWord = CommonService.GetJParamString(jParams, "passWord");
            string OrgNumber = CommonService.GetJParamString(jParams, "FCreateOrgId");
            string UseOrgNumber = CommonService.GetJParamString(jParams, "FUseOrgId");
            List<SqlParam> lstParam = new List<SqlParam>();
            if (string.IsNullOrWhiteSpace(OrgNumber))
            {
                result["Result"] = false;
                result["Message"] = "创建组织编码不能为空！";
                return result.ToString();
            }
            if (string.IsNullOrWhiteSpace(UseOrgNumber))
            {
                result["Result"] = false;
                result["Message"] = "使用组织编码不能为空！";
                return result.ToString();
            }
            string OrgId = CommonService.VKGetBaseDataIdByValue(ctx, OrgNumber);
            if (OrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FCreateOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string UseOrgId = CommonService.VKGetBaseDataIdByValue(ctx, UseOrgNumber);
            if (OrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FUseOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string CusNumber = CommonService.GetJParamString(jParams, "FNumber");
            if (string.IsNullOrWhiteSpace(CusNumber))
            {
                result["Result"] = false;
                result["Message"] = "客户编码不能为空！";
                return result.ToString();
            }
            string CusName = CommonService.GetJParamString(jParams, "FName");
            if (string.IsNullOrWhiteSpace(CusName))
            {
                result["Result"] = false;
                result["Message"] = "客户名称不能为空！";
                return result.ToString();
            }
            string FCustTypeId = CommonService.GetJParamString(jParams, "FCustTypeId");
            string FTHIRDSRCTYPE = CommonService.GetJParamString(jParams, "FTHIRDSRCTYPE");
            string FTHIRDBILLID = CommonService.GetJParamString(jParams, "FTHIRDBILLID");
            string FTHIRDBILLNO = CommonService.GetJParamString(jParams, "FTHIRDBILLNO");
            string FRetailerNO = CommonService.GetJParamString(jParams, "FRetailerNO");
            string FRetailerName = CommonService.GetJParamString(jParams, "FRetailerName");
            try
            {
                string metail = "{\"NeedUpDateFields\":[],\"NeedReturnFields\":[],\"IsDeleteEntry\":\"true\",\"SubSystemId\":\"\",\"IsVerifyBaseDataField\":\"false\",\"IsEntryBatchFill\":\"true\",\"ValidateFlag\":\"true\",\"NumberSearch\":\"true\",\"IsAutoAdjustField\":\"false\",\"InterationFlags\":\"\",\"IgnoreInterationFlag\":\"\",\"Model\":{\"FCUSTID\":0,\"FCreateOrgId\":{\"FNumber\":\"创建组织编码\"},\"FNumber\":\"客户编码\",\"FUseOrgId\":{\"FNumber\":\"使用组织编码\"},\"FName\":\"客户名称\",\"FCOUNTRY\":{\"FNumber\":\"China\"},\"FINVOICETITLE\":\"测试001\",\"FIsGroup\":false,\"FIsDefPayer\":false,\"FCustTypeId\":{\"FNumber\":\"KHLB001_SYS\"},\"FTRADINGCURRID\":{\"FNumber\":\"PRE001\"},\"FInvoiceType\":\"1\",\"FTaxType\":{\"FNumber\":\"SFL02_SYS\"},\"FPriority\":1,\"FTaxRate\":{\"FNumber\":\"SL02_SYS\"},\"FISCREDITCHECK\":true,\"FIsTrade\":true,\"FTHIRDSRCTYPE\":\"第三方来源\",\"FTHIRDBILLID\":\"第三方单据ID\",\"FTHIRDBILLNO\":\"第三方单据编号\",\"FRetailerNO\":\"零售商编码\",\"FRetailerName\":\"零售商名称\",\"FT_BD_CUSTOMEREXT\":{\"FEnableSL\":false,\"FALLOWJOINZHJ\":false}}}";
                metail = metail.Replace("创建组织编码", OrgId);
                metail = metail.Replace("使用组织编码", UseOrgId);
                metail = metail.Replace("客户编码", CusNumber);
                metail = metail.Replace("客户名称", CusName);
                metail = metail.Replace("零售商编码", FRetailerNO);
                metail = metail.Replace("零售商名称", FRetailerName);
                metail = metail.Replace("客户类别", FCustTypeId);
                metail = metail.Replace("第三方来源", FTHIRDSRCTYPE);
                metail = metail.Replace("第三方单据ID", FTHIRDBILLID);
                metail = metail.Replace("第三方单据编号", FTHIRDBILLNO);
                object saveres = WebApiServiceCall.Save(ctx, "BD_Customer", metail);
                JObject res = JObject.FromObject(saveres);
                JObject res1 = JObject.Parse(res["Result"].ToString());
                JObject res2 = JObject.Parse(res1["ResponseStatus"].ToString());
                if (!res2["SuccessEntitys"].ToString().Equals("[]"))
                {
                    JArray content = JArray.Parse(res2["SuccessEntitys"].ToString());
                    foreach (JObject List in content)
                    {
                        string fnumber = List["Number"].ToString();
                        string Submit = "{\"Numbers\":[\"编码\"]}";
                        Submit = Submit.Replace("编码", fnumber);
                        object sub = WebApiServiceCall.Submit(ctx, "BD_Customer", Submit);
                        JObject st1 = JObject.FromObject(sub);
                        JObject st2 = JObject.Parse(st1["Result"].ToString());
                        JObject st3 = JObject.Parse(st2["ResponseStatus"].ToString());
                        object aud = WebApiServiceCall.Audit(ctx, "BD_Customer", Submit);
                        JObject st4 = JObject.FromObject(aud);
                        JObject st5 = JObject.Parse(st4["Result"].ToString());
                        JObject st6 = JObject.Parse(st5["ResponseStatus"].ToString());
                    }
                }
                result["Result"] = true;
                result["Message"] = res["Result"].ToString();
            }
            catch (Exception e)
            {
                result["Result"] = false;
                result["Message"] = "数据格式不正确！" + e.Message;
            }
            return result.ToString();
        }

        internal string Supplier(Context ctx, string strParams, JObject result)
        {
            JObject jParams = JObject.Parse(strParams);
            string dataCenterID = CommonService.GetJParamString(jParams, "dataCenterID");
            string userName = CommonService.GetJParamString(jParams, "userName");
            string passWord = CommonService.GetJParamString(jParams, "passWord");
            string OrgNumber = CommonService.GetJParamString(jParams, "FCreateOrgId");
            string UseOrgNumber = CommonService.GetJParamString(jParams, "FUseOrgId");
            List<SqlParam> lstParam = new List<SqlParam>();
            if (string.IsNullOrWhiteSpace(OrgNumber))
            {
                result["Result"] = false;
                result["Message"] = "创建组织编码不能为空！";
                return result.ToString();
            }
            if (string.IsNullOrWhiteSpace(UseOrgNumber))
            {
                result["Result"] = false;
                result["Message"] = "使用组织编码不能为空！";
                return result.ToString();
            }
            string OrgId = CommonService.VKGetBaseDataIdByValue(ctx, OrgNumber);
            if (OrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FCreateOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string UseOrgId = CommonService.VKGetBaseDataIdByValue(ctx, UseOrgNumber);
            if (OrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FUseOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string CusNumber = CommonService.GetJParamString(jParams, "FNumber");
            if (string.IsNullOrWhiteSpace(CusNumber))
            {
                result["Result"] = false;
                result["Message"] = "供应商编码不能为空！";
                return result.ToString();
            }
            string CusName = CommonService.GetJParamString(jParams, "FName");
            if (string.IsNullOrWhiteSpace(CusName))
            {
                result["Result"] = false;
                result["Message"] = "供应商名称不能为空！";
                return result.ToString();
            }
            string FTHIRDSRCTYPE = CommonService.GetJParamString(jParams, "FTHIRDSRCTYPE");
            string FTHIRDBILLID = CommonService.GetJParamString(jParams, "FTHIRDBILLID");
            string FTHIRDBILLNO = CommonService.GetJParamString(jParams, "FTHIRDBILLNO");
            try
            {
                string metail = "{\"NeedUpDateFields\":[],\"NeedReturnFields\":[],\"IsDeleteEntry\":\"true\",\"SubSystemId\":\"\",\"IsVerifyBaseDataField\":\"false\",\"IsEntryBatchFill\":\"true\",\"ValidateFlag\":\"true\",\"NumberSearch\":\"true\",\"IsAutoAdjustField\":\"false\",\"InterationFlags\":\"\",\"IgnoreInterationFlag\":\"\",\"Model\":{\"FSupplierId\":0,\"FCreateOrgId\":{\"FNumber\":\"创建组织编码\"},\"FNumber\":\"供应商编码\",\"FUseOrgId\":{\"FNumber\":\"使用组织编码\"},\"FName\":\"供应商名称\",\"FTHIRDSRCTYPE\":\"第三方来源\",\"FTHIRDBILLID\":\"第三方单据ID\",\"FTHIRDBILLNO\":\"第三方单据编号\",\"FBaseInfo\":{\"FSupplyClassify\":\"CG\"},\"FBusinessInfo\":{\"FVmiBusiness\":false,\"FEnableSL\":false},\"FFinanceInfo\":{\"FPayCurrencyId\":{\"FNumber\":\"PRE001\"},\"FTaxType\":{\"FNumber\":\"SFL02_SYS\"},\"FInvoiceType\":\"1\",\"FTaxRateId\":{\"FNUMBER\":\"SL02_SYS\"}}}}";
                metail = metail.Replace("创建组织编码", OrgId);
                metail = metail.Replace("使用组织编码", UseOrgId);
                metail = metail.Replace("供应商编码", CusNumber);
                metail = metail.Replace("供应商名称", CusName);
                metail = metail.Replace("第三方来源", FTHIRDSRCTYPE);
                metail = metail.Replace("第三方单据ID", FTHIRDBILLID);
                metail = metail.Replace("第三方单据编号", FTHIRDBILLNO);
                object saveres = WebApiServiceCall.Save(ctx, "BD_Supplier", metail);
                JObject res = JObject.FromObject(saveres);
                JObject res1 = JObject.Parse(res["Result"].ToString());
                JObject res2 = JObject.Parse(res1["ResponseStatus"].ToString());
                if (!res2["SuccessEntitys"].ToString().Equals("[]"))
                {
                    JArray content = JArray.Parse(res2["SuccessEntitys"].ToString());
                    foreach (JObject List in content)
                    {
                        string fnumber = List["Number"].ToString();
                        string Submit = "{\"Numbers\":[\"编码\"]}";
                        Submit = Submit.Replace("编码", fnumber);
                        object sub = WebApiServiceCall.Submit(ctx, "BD_Supplier", Submit);
                        JObject st1 = JObject.FromObject(sub);
                        JObject st2 = JObject.Parse(st1["Result"].ToString());
                        JObject st3 = JObject.Parse(st2["ResponseStatus"].ToString());
                        object aud = WebApiServiceCall.Audit(ctx, "BD_Supplier", Submit);
                        JObject st4 = JObject.FromObject(aud);
                        JObject st5 = JObject.Parse(st4["Result"].ToString());
                        JObject st6 = JObject.Parse(st5["ResponseStatus"].ToString());
                    }
                }
                result["Result"] = true;
                result["Message"] = res["Result"].ToString();
            }
            catch (Exception e)
            {
                result["Result"] = false;
                result["Message"] = "数据格式不正确！" + e.Message;
            }
            return result.ToString();
        }

        internal string STOCK(Context ctx, string strParams, JObject result)
        {
            JObject jParams = JObject.Parse(strParams);
            string dataCenterID = CommonService.GetJParamString(jParams, "dataCenterID");
            string userName = CommonService.GetJParamString(jParams, "userName");
            string passWord = CommonService.GetJParamString(jParams, "passWord");
            string OrgNumber = CommonService.GetJParamString(jParams, "FCreateOrgId");
            string UseOrgNumber = CommonService.GetJParamString(jParams, "FUseOrgId");
            List<SqlParam> lstParam = new List<SqlParam>();
            string StockProperty = "";
            if (string.IsNullOrWhiteSpace(OrgNumber))
            {
                result["Result"] = false;
                result["Message"] = "创建组织编码不能为空！";
                return result.ToString();
            }
            if (string.IsNullOrWhiteSpace(UseOrgNumber))
            {
                result["Result"] = false;
                result["Message"] = "使用组织编码不能为空！";
                return result.ToString();
            }
            string OrgId = CommonService.VKGetBaseDataIdByValue(ctx, OrgNumber);
            if (OrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FCreateOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string UseOrgId = CommonService.VKGetBaseDataIdByValue(ctx, UseOrgNumber);
            if (OrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FUseOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string CusNumber = CommonService.GetJParamString(jParams, "FNumber");
            if (string.IsNullOrWhiteSpace(CusNumber))
            {
                result["Result"] = false;
                result["Message"] = "仓库编码不能为空！";
                return result.ToString();
            }
            string CusName = CommonService.GetJParamString(jParams, "FName");
            if (string.IsNullOrWhiteSpace(CusName))
            {
                result["Result"] = false;
                result["Message"] = "仓库名称不能为空！";
                return result.ToString();
            }
            string FTHIRDSRCTYPE = CommonService.GetJParamString(jParams, "FTHIRDSRCTYPE");
            string FTHIRDBILLID = CommonService.GetJParamString(jParams, "FTHIRDBILLID");
            string FTHIRDBILLNO = CommonService.GetJParamString(jParams, "FTHIRDBILLNO");
            string FStockProperty = CommonService.GetJParamString(jParams, "FStockProperty");
            if (FStockProperty == "客户仓库")
            {
                StockProperty = "4";
            }
            else 
            {
                StockProperty = "1";
            }
            string FCustomerId = CommonService.GetJParamString(jParams, "FCustomerId");
            try
            {
                string metail = "{\"NeedUpDateFields\":[],\"NeedReturnFields\":[],\"IsDeleteEntry\":\"true\",\"SubSystemId\":\"\",\"IsVerifyBaseDataField\":\"false\",\"IsEntryBatchFill\":\"true\",\"ValidateFlag\":\"true\",\"NumberSearch\":\"true\",\"IsAutoAdjustField\":\"false\",\"InterationFlags\":\"\",\"IgnoreInterationFlag\":\"\",\"Model\":{\"FStockId\":0,\"FCreateOrgId\":{\"FNumber\":\"创建组织编码\"},\"FNumber\":\"仓库编码\",\"FUseOrgId\":{\"FNumber\":\"使用组织编码\"},\"FName\":\"仓库名称\",\"FTHIRDSRCTYPE\":\"第三方来源\",\"FTHIRDBILLID\":\"第三方单据ID\",\"FTHIRDBILLNO\":\"第三方单据编号\",\"FStockProperty\":\"仓库属性\",\"FStockStatusType\":\"0,1,2,3,4,5,6,7,8\",\"FDefReceiveStatusId\":{\"FNumber\":\"KCZT02_SYS\"},\"FDefStockStatusId\":{\"FNumber\":\"KCZT01_SYS\"},\"FAllowMinusQty\":false,\"FIsGYStock\":false,\"FAllowLock\":true,\"FNotExpQty\":false,\"FIsOpenLocation\":false,\"FAllowMRPPlan\":true,\"FAvailablePicking\":true,\"FAvailableAlert\":true,\"FSortingPriority\":1}}";
                metail = metail.Replace("创建组织编码", OrgId);
                metail = metail.Replace("使用组织编码", UseOrgId);
                metail = metail.Replace("仓库编码", CusNumber);
                metail = metail.Replace("仓库名称", CusName);
                metail = metail.Replace("仓库属性", StockProperty);
                metail = metail.Replace("客户", FCustomerId);
                metail = metail.Replace("第三方来源", FTHIRDSRCTYPE);
                metail = metail.Replace("第三方单据ID", FTHIRDBILLID);
                metail = metail.Replace("第三方单据编号", FTHIRDBILLNO);
                object saveres = WebApiServiceCall.Save(ctx, "BD_STOCK", metail);
                JObject res = JObject.FromObject(saveres);
                JObject res1 = JObject.Parse(res["Result"].ToString());
                JObject res2 = JObject.Parse(res1["ResponseStatus"].ToString());
                if (!res2["SuccessEntitys"].ToString().Equals("[]"))
                {
                    JArray content = JArray.Parse(res2["SuccessEntitys"].ToString());
                    foreach (JObject List in content)
                    {
                        string fnumber = List["Number"].ToString();
                        string Submit = "{\"Numbers\":[\"编码\"]}";
                        Submit = Submit.Replace("编码", fnumber);
                        object sub = WebApiServiceCall.Submit(ctx, "BD_STOCK", Submit);
                        JObject st1 = JObject.FromObject(sub);
                        JObject st2 = JObject.Parse(st1["Result"].ToString());
                        JObject st3 = JObject.Parse(st2["ResponseStatus"].ToString());
                        object aud = WebApiServiceCall.Audit(ctx, "BD_STOCK", Submit);
                        JObject st4 = JObject.FromObject(aud);
                        JObject st5 = JObject.Parse(st4["Result"].ToString());
                        JObject st6 = JObject.Parse(st5["ResponseStatus"].ToString());
                    }
                }
                result["Result"] = true;
                result["Message"] = res["Result"].ToString();
            }
            catch (Exception e)
            {
                result["Result"] = false;
                result["Message"] = "数据格式不正确！" + e.Message;
            }
            return result.ToString();
        }

        //public static bool SaveMethod(Context context, string FormId, string jsonData, string file)
        //{
        //    StringBuilder stringBuilder = new StringBuilder();//接收失败原因
        //    object saveResult = WebApiServiceCall.Save(context, FormId, jsonData);//调用保存方法  
        //    Dictionary<String, object> responseStatus = ((Dictionary<String, object>)((Dictionary<String, object>)saveResult)["Result"])["ResponseStatus"] as Dictionary<String, object>;
        //    if (responseStatus["IsSuccess"].ToString() == "True")
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        List<object> errors = responseStatus["Errors"] as List<object>;
        //        for (int a = 0; a < errors.Count(); a++)
        //        {
        //            Dictionary<string, object> keyValues = errors[a] as Dictionary<string, object>;
        //            stringBuilder.AppendLine("第" + keyValues["DIndex"] + "行分录:" + keyValues["Message"]);
        //        }
        //        Logger.Info(file + "生成编码为物料失败，原因如下：", stringBuilder.ToString());
        //        return false;
        //    }
        //}
        internal string PriceList(Context ctx, string strParams, JObject result)
        {
            JObject jParams = JObject.Parse(strParams);
            string dataCenterID = CommonService.GetJParamString(jParams, "dataCenterID");
            string userName = CommonService.GetJParamString(jParams, "userName");
            string passWord = CommonService.GetJParamString(jParams, "passWord");
            string OrgNumber = CommonService.GetJParamString(jParams, "FCreateOrgId");
            string UseOrgNumber = CommonService.GetJParamString(jParams, "FUseOrgId");
            string FEntryEffectiveDate = "";
            string FEntryExpriyDate = "";
            string FMATERIALID = "";
            string FPRICEUNITID = "";
            string FTaxPrice = "";
            List<SqlParam> lstParam = new List<SqlParam>();
            if (string.IsNullOrWhiteSpace(OrgNumber))
            {
                result["Result"] = false;
                result["Message"] = "创建组织编码不能为空！";
                return result.ToString();
            }
            if (string.IsNullOrWhiteSpace(UseOrgNumber))
            {
                result["Result"] = false;
                result["Message"] = "使用组织编码不能为空！";
                return result.ToString();
            }
            string OrgId = CommonService.VKGetBaseDataIdByValue(ctx, OrgNumber);
            if (OrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FCreateOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string UseOrgId = CommonService.VKGetBaseDataIdByValue(ctx, UseOrgNumber);
            if (OrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FUseOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string CusNumber = CommonService.GetJParamString(jParams, "FBillNo");
            if (string.IsNullOrWhiteSpace(CusNumber))
            {
                result["Result"] = false;
                result["Message"] = "单据编号不能为空！";
                return result.ToString();
            }
            string CusName = CommonService.GetJParamString(jParams, "FName");
            if (string.IsNullOrWhiteSpace(CusName))
            {
                result["Result"] = false;
                result["Message"] = "单据名称不能为空！";
                return result.ToString();
            }
            string FEffectiveDATE = CommonService.GetJParamString(jParams, "FEffectiveDATE");
            string FEXPIRYDATE = CommonService.GetJParamString(jParams, "FEXPIRYDATE");

            string entity_post_data = "";
            string metails = "";
            try
            {
                List<string> entitys = new List<string>();
                //商品信息
                JArray materail = JArray.Parse(jParams["FMaterial"].ToString());
                foreach (JObject List in materail)
                {
                    metails = "{\"FMATERIALID\":{\"FNumber\":\"物料\"},\"FTRADETYPE\":\"物料\",\"FPRICEBASE\":1.0,\"FTaxPrice\":含税单价,\"FIsFreeGift\":false,\"FEntryEffectiveDate\":\"分录生日期\",\"FEntryExpriyDate\":\"分录失日期\",\"FRowAuditStatus\":\"U\"}";
                    FMATERIALID = List["FMATERIALID"].ToString();
                    FEntryEffectiveDate = List["FEntryEffectiveDate"].ToString();
                    FEntryExpriyDate = List["FEntryExpriyDate"].ToString();
                    FPRICEUNITID = List["FPRICEUNITID"].ToString();
                    FTaxPrice = List["FTaxPrice"].ToString();
                    FMATERIALID = CommonService.VKFMaterialId(ctx, FMATERIALID);
                    if (FMATERIALID == "0")
                    {
                        result["Result"] = false;
                        result["Message"] = "商品不存在！";
                        return result.ToString();
                    }
                    metails = metails.Replace("分录生日期", FEntryEffectiveDate);
                    metails = metails.Replace("分录失日期", FEntryExpriyDate);
                    //metails = metails.Replace("定价单位", FPRICEUNITID);
                    metails = metails.Replace("含税单价", FTaxPrice);
                    metails = metails.Replace("物料", FMATERIALID);
                    entitys.Add(metails);
                }
                if (entitys.Count > 0)
                {
                    for (int j = 0; j < entitys.Count; j++)
                    {
                        entity_post_data = entity_post_data + entitys[j] + ",";
                    }
                }
                entity_post_data = entity_post_data.Remove(entity_post_data.Length - 1, 1);
                string metail = "{\"NeedUpDateFields\":[],\"NeedReturnFields\":[],\"IsDeleteEntry\":\"true\",\"SubSystemId\":\"\",\"IsVerifyBaseDataField\":\"false\",\"IsEntryBatchFill\":\"true\",\"ValidateFlag\":\"true\",\"NumberSearch\":\"true\",\"IsAutoAdjustField\":\"false\",\"InterationFlags\":\"\",\"IgnoreInterationFlag\":\"\",\"Model\":{\"FID\":0,\"FAuditStatus\":\"U\",\"FCreateOrgId\":{\"FNumber\":\"创建组织编码\"},\"FNumber\":\"编码\",\"FIsIncludedTax\":false,\"FName\":\"名称\",\"FPRICETYPE\":\"Material\",\"FCURRENCYID\":{\"FNumber\":\"PRE001\"},\"FUseOrgId\":{\"FNumber\":\"使用组织编码\"},\"FEffectiveDATE\":\"生效日\",\"FEXPIRYDATE\":\"失效日\",\"FEntity\":[明细],\"FEntityAcctSys\":[{\"FIsEnable\":true,\"FACCTSysId\":{\"FNumber\":\"KJHSTX01_SYS\"}}]}}";
                metail = metail.Replace("创建组织编码", OrgId);
                metail = metail.Replace("使用组织编码", UseOrgId);
                metail = metail.Replace("编码", CusNumber);
                metail = metail.Replace("名称", CusName);
                metail = metail.Replace("生效日", FEffectiveDATE);
                metail = metail.Replace("失效日", FEXPIRYDATE);
                metail = metail.Replace("明细", entity_post_data);
                object saveres = WebApiServiceCall.Save(ctx, "IOS_PriceList", metail);
                JObject res = JObject.FromObject(saveres);
                JObject res1 = JObject.Parse(res["Result"].ToString());
                JObject res2 = JObject.Parse(res1["ResponseStatus"].ToString());
                if (!res2["SuccessEntitys"].ToString().Equals("[]"))
                {
                    JArray content = JArray.Parse(res2["SuccessEntitys"].ToString());
                    foreach (JObject List in content)
                    {
                        string fnumber = List["Number"].ToString();
                        string Submit = "{\"Numbers\":[\"编码\"]}";
                        Submit = Submit.Replace("编码", fnumber);
                        object sub = WebApiServiceCall.Submit(ctx, "IOS_PriceList", Submit);
                        JObject st1 = JObject.FromObject(sub);
                        JObject st2 = JObject.Parse(st1["Result"].ToString());
                        JObject st3 = JObject.Parse(st2["ResponseStatus"].ToString());
                        object aud = WebApiServiceCall.Audit(ctx, "IOS_PriceList", Submit);
                        JObject st4 = JObject.FromObject(aud);
                        JObject st5 = JObject.Parse(st4["Result"].ToString());
                        JObject st6 = JObject.Parse(st5["ResponseStatus"].ToString());
                    }
                }
                result["Result"] = true;
                result["Message"] = res["Result"].ToString();
            }
            catch (Exception e)
            {
                result["Result"] = false;
                result["Message"] = "数据格式不正确！" + e.Message;
            }
            return result.ToString();
        }

        internal string AdjustPrice(Context ctx, string strParams, JObject result)
        {
            JObject jParams = JObject.Parse(strParams);
            string dataCenterID = CommonService.GetJParamString(jParams, "dataCenterID");
            string userName = CommonService.GetJParamString(jParams, "userName");
            string passWord = CommonService.GetJParamString(jParams, "passWord");
            string OrgNumber = CommonService.GetJParamString(jParams, "FSaleOrgId");
            string FMATERIALID = "";
            string FPriceListId = "";
            string FAfterTaxPrice = "";
            string FPriceUnitId = "";
            string FAdjustType = "";
            string FAfterEffectiveDate = "";
            string FAfterExpiryDate = "";
            string AdjustType = "";


            List<SqlParam> lstParam = new List<SqlParam>();
            if (string.IsNullOrWhiteSpace(OrgNumber))
            {
                result["Result"] = false;
                result["Message"] = "创建组织编码不能为空！";
                return result.ToString();
            }
            string OrgId = CommonService.VKGetBaseDataIdByValue(ctx, OrgNumber);
            if (OrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FSaleOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string CusNumber = CommonService.GetJParamString(jParams, "FBillNo");
            if (string.IsNullOrWhiteSpace(CusNumber))
            {
                result["Result"] = false;
                result["Message"] = "单据编号不能为空！";
                return result.ToString();
            }
            string CusName = CommonService.GetJParamString(jParams, "FName");
            if (string.IsNullOrWhiteSpace(CusName))
            {
                result["Result"] = false;
                result["Message"] = "单据名称不能为空！";
                return result.ToString();
            }
            string FDate = CommonService.GetJParamString(jParams, "FDate");
            if (string.IsNullOrWhiteSpace(FDate))
            {
                result["Result"] = false;
                result["Message"] = "单据日期不能为空！";
                return result.ToString();
            }
            //string Date = Convert.ToDateTime(FDate).ToString("yyyy-MM-dd HH:mm:ss");
            //商品信息
            string metails = "";
            string entity_post_data = "";
            try
            {

                List<string> entitys = new List<string>();
                JArray materail = JArray.Parse(jParams["FADJUSTPRICEENTRY"].ToString());

                foreach (JObject List in materail)
                {
                    metails = "{\"FAdjustType\":\"调价类型\",\"FPriceListId\":{\"FNUMBER\":\"价目表\"},\"FCurrencyId\":{\"FNUMBER\":\"PRE001\"},\"FIsIncludedTax\":false,\"FMaterialId\":{\"FNumber\":\"物料\"},\"FAfterPrice\":调后含税单价,\"FAfterTaxPrice\":调后含税单价,\"FAfterEffectiveDate\":\"生日\",\"FAfterExpiryDate\":\"失日\"}";
                    FMATERIALID = List["FMaterialId"].ToString();
                    FMATERIALID = CommonService.VKFMaterialId(ctx, FMATERIALID);
                    if (FMATERIALID == "0")
                    {
                        result["Result"] = false;
                        result["Message"] = "商品不存在！";
                        return result.ToString();
                    }
                    FPriceListId = List["FPriceListId"].ToString();
                    FAfterTaxPrice = List["FAfterTaxPrice"].ToString();
                    FPriceUnitId = List["FPriceUnitId"].ToString();
                    FAdjustType = List["FAdjustType"].ToString();
                    if (FAdjustType == "新增")
                    {
                        AdjustType = "A";
                    }
                    else
                    {
                        AdjustType = "B";
                    }
                    FAfterEffectiveDate = List["FAfterEffectiveDate"].ToString();
                    FAfterExpiryDate = List["FAfterExpiryDate"].ToString();
                    metails = metails.Replace("物料", FMATERIALID);
                    metails = metails.Replace("调后含税单价", FAfterTaxPrice);
                    metails = metails.Replace("价目表", FPriceListId);
                    //metails = metails.Replace("计价单位", FPriceUnitId);
                    metails = metails.Replace("调价类型", AdjustType);
                    metails = metails.Replace("生日", FAfterEffectiveDate.Replace(" ", ""));
                    metails = metails.Replace("失日", FAfterExpiryDate.Replace(" ", ""));
                    entitys.Add(metails);
                }
                if (entitys.Count > 0)
                {
                    for (int j = 0; j < entitys.Count; j++)
                    {
                        entity_post_data = entity_post_data + entitys[j] + ",";
                    }
                }
                entity_post_data = entity_post_data.Remove(entity_post_data.Length - 1, 1);
                string metail = "{\"NeedUpDateFields\":[],\"NeedReturnFields\":[],\"IsDeleteEntry\":\"true\",\"SubSystemId\":\"\",\"IsVerifyBaseDataField\":\"false\",\"IsEntryBatchFill\":\"true\",\"ValidateFlag\":\"true\",\"NumberSearch\":\"true\",\"InterationFlags\":\"\",\"Model\":{\"FID\":0,\"FName\":\"名称\",\"FDate\":\"单据日期\",\"FSaleOrgId\":{\"FNumber\":\"创建组织编码\"},\"FPlanEffectiveDate\":\"单据日期\",\"FBillNo\":\"编码\",\"FADJUSTPRICEENTRY\":[明细]}}";
                metail = metail.Replace("创建组织编码", OrgId);
                metail = metail.Replace("编码", CusNumber);
                metail = metail.Replace("名称", CusName);
                metail = metail.Replace("单据日期", FDate);
                metail = metail.Replace("明细", entity_post_data);
                object saveres = WebApiServiceCall.Save(ctx, "IOS_AdjustPrice", metail);
                JObject res = JObject.FromObject(saveres);
                JObject res1 = JObject.Parse(res["Result"].ToString());
                JObject res2 = JObject.Parse(res1["ResponseStatus"].ToString());
                if (!res2["SuccessEntitys"].ToString().Equals("[]"))
                {
                    JArray content = JArray.Parse(res2["SuccessEntitys"].ToString());
                    foreach (JObject List in content)
                    {
                        string fnumber = List["Number"].ToString();
                        string Submit = "{\"Numbers\":[\"编码\"]}";
                        Submit = Submit.Replace("编码", fnumber);
                        object sub = WebApiServiceCall.Submit(ctx, "IOS_AdjustPrice", Submit);
                        JObject st1 = JObject.FromObject(sub);
                        JObject st2 = JObject.Parse(st1["Result"].ToString());
                        JObject st3 = JObject.Parse(st2["ResponseStatus"].ToString());
                        object aud = WebApiServiceCall.Audit(ctx, "IOS_AdjustPrice", Submit);
                        JObject st4 = JObject.FromObject(aud);
                        JObject st5 = JObject.Parse(st4["Result"].ToString());
                        JObject st6 = JObject.Parse(st5["ResponseStatus"].ToString());
                    }
                }
                result["Result"] = true;
                result["Message"] = res["Result"].ToString();
            }
            catch (Exception e)
            {
                result["Result"] = false;
                result["Message"] = "数据格式不正确！" + e.Message;
            }
            return result.ToString();
        }

        internal string InStock(Context ctx, string strParams, JObject result)
        {
            JObject jParams = JObject.Parse(strParams);
            string dataCenterID = CommonService.GetJParamString(jParams, "dataCenterID");
            string userName = CommonService.GetJParamString(jParams, "userName");
            string passWord = CommonService.GetJParamString(jParams, "passWord");
            string FStockOrgId = CommonService.GetJParamString(jParams, "FStockOrgId");
            string FDate = CommonService.GetJParamString(jParams, "FDate");
            string FBillTypeID = CommonService.GetJParamString(jParams, "FBillTypeID");
            string FOwnerIdHead = CommonService.GetJParamString(jParams, "FOwnerIdHead");
            string FDemandOrgId = CommonService.GetJParamString(jParams, "FDemandOrgId");
            string FPurchaseOrgId = CommonService.GetJParamString(jParams, "FPurchaseOrgId");
            string FSupplierId = CommonService.GetJParamString(jParams, "FSupplierId");
            string FThirdSrcId = CommonService.GetJParamString(jParams, "FThirdSrcId");
            string FThirdSrcBillNo = CommonService.GetJParamString(jParams, "FThirdSrcBillNo");
            string FThirdSystem = CommonService.GetJParamString(jParams, "FThirdSystem");
            string FHeadNote = CommonService.GetJParamString(jParams, "FHeadNote");
            string FSettleOrgId = "";
            string FMaterialId = "";
            string FStockId = "";
            string FMustQty = "";
            string FRealQty = "";
            string FOWNERID = "";

            List<SqlParam> lstParam = new List<SqlParam>();
            string StockOrgId = CommonService.VKGetBaseDataIdByValue(ctx, FStockOrgId);
            if (StockOrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FStockOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string OwnerIdHead = CommonService.VKGetBaseDataIdByValue(ctx, FOwnerIdHead);
            if (OwnerIdHead == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FOwnerIdHead：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string DemandOrgId = CommonService.VKGetBaseDataIdByValue(ctx, FDemandOrgId);
            if (DemandOrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FDemandOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string PurchaseOrgId = CommonService.VKGetBaseDataIdByValue(ctx, FPurchaseOrgId);
            if (PurchaseOrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FPurchaseOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string FBillNo = CommonService.GetJParamString(jParams, "FBillNo");
            if (string.IsNullOrWhiteSpace(FBillNo))
            {
                result["Result"] = false;
                result["Message"] = "单据编号不能为空！";
                return result.ToString();
            }
            //商品信息
            JArray InStockFin = JArray.Parse(jParams["FInStockFin"].ToString());
            foreach (JObject List in InStockFin)
            {
                FSettleOrgId = List["FSettleOrgId"].ToString();
            }
            string SettleOrgId = CommonService.VKGetBaseDataIdByValue(ctx, FSettleOrgId);
            if (SettleOrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FSettleOrgId】在系统中不存在！";
                return result.ToString();
            }
            string OWNERID = "";
            string metail = "";
            string entity_post_data = "";
            try
            {
                List<string> entitys = new List<string>();
                //物料
                JArray FInStockEntry = JArray.Parse(jParams["FInStockEntry"].ToString());
                foreach (JObject List in FInStockEntry)
                {

                    metail = "{\"FRowType\":\"Standard\",\"FMaterialId\":{\"FNumber\":\"物料编码\"},\"FRealQty\":实收数量,\"FStockId\":{\"FNumber\":\"仓库\"},\"FStockStatusId\":{\"FNumber\":\"KCZT01_SYS\"},\"FGiveAway\":false,\"FOWNERTYPEID\":\"BD_OwnerOrg\",\"FCheckInComing\":false,\"FIsReceiveUpdateStock\":false,\"FBILLINGCLOSE\":false,\"FEntryTaxRate\":13.00,\"FOWNERID\":{\"FNumber\":\"货主\"}}";
                    FMaterialId = List["FMaterialId"].ToString();
                    FStockId = List["FStockId"].ToString();
                    FMustQty = List["FMustQty"].ToString();
                    FRealQty = List["FRealQty"].ToString();
                    FOWNERID = List["FOWNERID"].ToString();
                    OWNERID = CommonService.VKGetBaseDataIdByValue(ctx, FOWNERID);
                    FMaterialId = CommonService.VKFMaterialId(ctx, FMaterialId);
                    if (FMaterialId == "0")
                    {
                        result["Result"] = false;
                        result["Message"] = "商品不存在！";
                        return result.ToString();
                    }
                    FStockId = CommonService.VKFStockId(ctx, FStockId);
                    metail = metail.Replace("物料编码", FMaterialId);
                    metail = metail.Replace("仓库", FStockId);
                    metail = metail.Replace("应收数量", FMustQty);
                    metail = metail.Replace("实收数量", FRealQty);
                    metail = metail.Replace("货主", OWNERID);
                    entitys.Add(metail);
                }
                if (entitys.Count > 0)
                {
                    for (int j = 0; j < entitys.Count; j++)
                    {
                        entity_post_data = entity_post_data + entitys[j] + ",";
                    }
                }
                entity_post_data = entity_post_data.Remove(entity_post_data.Length - 1, 1);
                string metails = "{\"NeedUpDateFields\":[],\"NeedReturnFields\":[],\"IsDeleteEntry\":\"true\",\"SubSystemId\":\"\",\"IsVerifyBaseDataField\":\"false\",\"IsEntryBatchFill\":\"true\",\"ValidateFlag\":\"true\",\"NumberSearch\":\"true\",\"IsAutoAdjustField\":\"false\",\"InterationFlags\":\"\",\"IgnoreInterationFlag\":\"\",\"Model\":{\"FID\":0,\"FBillTypeID\":{\"FNUMBER\":\"单据类型\"},\"FBillNo\":\"单据编号\",\"FDate\":\"入库日期\",\"FStockOrgId\":{\"FNumber\":\"收料组织\"},\"FDemandOrgId\":{\"FNumber\":\"需求组织\"},\"FPurchaseOrgId\":{\"FNumber\":\"采购组织\"},\"FSupplierId\":{\"FNumber\":\"供应商\"},\"FSupplyId\":{\"FNumber\":\"SPCHN043607\"},\"FSettleId\":{\"FNumber\":\"SPCHN043607\"},\"FChargeId\":{\"FNumber\":\"SPCHN043607\"},\"FOwnerTypeIdHead\":\"BD_OwnerOrg\",\"FOwnerIdHead\":{\"FNumber\":\"货主\"},\"FSplitBillType\":\"A\",\"FInStockFin\":{\"FSettleOrgId\":{\"FNumber\":\"结算组织\"},\"FSettleCurrId\":{\"FNumber\":\"PRE001\"},\"FIsIncludedTax\":true,\"FPriceTimePoint\":\"1\",\"FLocalCurrId\":{\"FNumber\":\"PRE001\"},\"FExchangeTypeId\":{\"FNumber\":\"HLTX01_SYS\"},\"FExchangeRate\":1.0,\"FISPRICEEXCLUDETAX\":true},\"FInStockEntry\":[明细]}}";
                metails = metails.Replace("单据编号", FBillNo);
                metails = metails.Replace("收料组织", StockOrgId);
                metails = metails.Replace("入库日期", FDate);
                metails = metails.Replace("单据类型", FBillTypeID);
                metails = metails.Replace("货主", OwnerIdHead);
                metails = metails.Replace("需求组织", DemandOrgId);
                metails = metails.Replace("采购组织", PurchaseOrgId);
                FSupplierId = CommonService.VKFSupplierId(ctx, FSupplierId);
                metails = metails.Replace("供应商", FSupplierId);
                metails = metails.Replace("结算组织", SettleOrgId);
                metails = metails.Replace("明细", entity_post_data);
                object saveres = WebApiServiceCall.Save(ctx, "STK_InStock", metails);
                JObject res = JObject.FromObject(saveres);
                JObject res1 = JObject.Parse(res["Result"].ToString());
                JObject res2 = JObject.Parse(res1["ResponseStatus"].ToString());
                result["Result"] = true;
                result["Message"] = res["Result"].ToString();

            }
            catch (Exception e)
            {
                result["Result"] = false;
                result["Message"] = "数据格式不正确！" + e.Message;
            }
            return result.ToString();
        }

        internal string OUTSTOCK(Context ctx, string strParams, JObject result)
        {
            JObject jParams = JObject.Parse(strParams);
            string dataCenterID = CommonService.GetJParamString(jParams, "dataCenterID");
            string userName = CommonService.GetJParamString(jParams, "userName");
            string passWord = CommonService.GetJParamString(jParams, "passWord");
            string FBillNo = CommonService.GetJParamString(jParams, "FBillNo");
            if (string.IsNullOrWhiteSpace(FBillNo))
            {
                result["Result"] = false;
                result["Message"] = "单据编号不能为空！";
                return result.ToString();
            }
            string FSettleOrgId = "";
            string FMaterialId = "";
            string FStockId = "";
            string FMustQty = "";
            string FRealQty = "";
            string FOWNERID = "";
            string FBillAllAmount = "";
            string FAllAmount = "";
            string FEntrynote = "";
            string FTaxPrice = "";
            string FSaleOrgId = CommonService.GetJParamString(jParams, "FSaleOrgId");
            string FDate = CommonService.GetJParamString(jParams, "FDate");
            string FBillTypeID = CommonService.GetJParamString(jParams, "FBillTypeID");
            string FStockOrgId = CommonService.GetJParamString(jParams, "FStockOrgId");
            string FCustomerID = CommonService.GetJParamString(jParams, "FCustomerID");
            string FOwnerIdHead = CommonService.GetJParamString(jParams, "FOwnerIdHead");
            string FThirdSrcId = CommonService.GetJParamString(jParams, "FThirdSrcId");
            string FThirdSrcBillNo = CommonService.GetJParamString(jParams, "FThirdSrcBillNo");
            string FThirdSystem = CommonService.GetJParamString(jParams, "FThirdSystem");
            string FNote = CommonService.GetJParamString(jParams, "FNote");
            string OWNERID = "";
            string metail = "";


            string SaleOrgId = CommonService.VKGetBaseDataIdByValue(ctx, FSaleOrgId);
            if (SaleOrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FSaleOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string OwnerIdHead = CommonService.VKGetBaseDataIdByValue(ctx, FOwnerIdHead);
            if (OwnerIdHead == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FOwnerIdHead：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string StockOrgId = CommonService.VKGetBaseDataIdByValue(ctx, FStockOrgId);
            if (StockOrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FStockOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            //商品信息
            JArray FSubHeadEntity = JArray.Parse(jParams["FSubHeadEntity"].ToString());
            foreach (JObject List in FSubHeadEntity)
            {
                FSettleOrgId = List["FSettleOrgID"].ToString();
                FBillAllAmount = List["FBillAllAmount"].ToString();
            }
            string SettleOrgId = CommonService.VKGetBaseDataIdByValue(ctx, FSettleOrgId);
            if (SettleOrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FSettleOrgId】在系统中不存在！";
                return result.ToString();
            }
            string entity_post_data = "";
            try
            {
                List<string> entitys = new List<string>();
                //物料
                JArray FEntity = JArray.Parse(jParams["FEntity"].ToString());
                foreach (JObject List in FEntity)
                {
                    metail = "{\"FRowType\":\"Standard\",\"FMaterialID\":{\"FNumber\":\"物料编码\"},\"FRealQty\":实收数量,\"FTaxPrice\":含税单价,\"FIsFree\":false,\"FOwnerTypeID\":\"BD_OwnerOrg\",\"FOwnerID\":{\"FNumber\":\"货主\"},\"FEntryTaxRate\":13.00,\"FStockID\":{\"FNumber\":\"仓库\"},\"FStockStatusID\":{\"FNumber\":\"KCZT01_SYS\"},\"FEntrynote\":\"分录备注\",\"FOUTCONTROL\":false,\"FIsOverLegalOrg\":false,\"FCheckDelivery\":false}";
                    FMaterialId = List["FMaterialID"].ToString();
                    FStockId = List["FStockID"].ToString();
                    FMustQty = List["FMustQty"].ToString();
                    FRealQty = List["FRealQty"].ToString();
                    FOWNERID = List["FOwnerID"].ToString();
                    FAllAmount = List["FAllAmount"].ToString();
                    FEntrynote = List["FEntrynote"].ToString();
                    FTaxPrice = List["FTaxPrice"].ToString();
                    OWNERID = CommonService.VKGetBaseDataIdByValue(ctx, FOWNERID);
                    FMaterialId = CommonService.VKFMaterialId(ctx, FMaterialId);
                    if (FMaterialId == "0")
                    {
                        result["Result"] = false;
                        result["Message"] = "商品不存在！";
                        return result.ToString();
                    }
                    FStockId = CommonService.VKFStockId(ctx, FStockId);
                    metail = metail.Replace("物料编码", FMaterialId);
                    metail = metail.Replace("仓库", FStockId);
                    //metail = metail.Replace("应收数量", FMustQty);
                    metail = metail.Replace("实收数量", FRealQty);
                    metail = metail.Replace("货主", OWNERID);
                    metail = metail.Replace("含税单价", FTaxPrice);
                    //metail = metail.Replace("价税合计", FAllAmount);
                    metail = metail.Replace("分录备注", FEntrynote);
                    entitys.Add(metail);
                }
                if (entitys.Count > 0)
                {
                    for (int j = 0; j < entitys.Count; j++)
                    {
                        entity_post_data = entity_post_data + entitys[j] + ",";
                    }
                }
                entity_post_data = entity_post_data.Remove(entity_post_data.Length - 1, 1);
                string metails = "{\"NeedUpDateFields\":[],\"NeedReturnFields\":[],\"IsDeleteEntry\":\"true\",\"SubSystemId\":\"\",\"IsVerifyBaseDataField\":\"false\",\"IsEntryBatchFill\":\"true\",\"ValidateFlag\":\"true\",\"NumberSearch\":\"true\",\"IsAutoAdjustField\":\"false\",\"InterationFlags\":\"\",\"IgnoreInterationFlag\":\"\",\"Model\":{\"FID\":0,\"FBillTypeID\":{\"FNUMBER\":\"单据类型\"},\"FBillNo\":\"单据编号\",\"FDate\":\"日期\",\"FSaleOrgId\":{\"FNumber\":\"销售组织\"},\"FCustomerID\":{\"FNumber\":\"客户\"},\"FStockOrgId\":{\"FNumber\":\"发货组织\"},\"FOwnerTypeIdHead\":\"BD_OwnerOrg\",\"FIsTotalServiceOrCost\":false,\"SubHeadEntity\":{\"FSettleCurrID\":{\"FNumber\":\"PRE001\"},\"FSettleOrgID\":{\"FNumber\":\"结算组织\"},\"FIsIncludedTax\":true,\"FLocalCurrID\":{\"FNumber\":\"PRE001\"},\"FExchangeTypeID\":{\"FNumber\":\"HLTX01_SYS\"},\"FExchangeRate\":1.0,\"FIsPriceExcludeTax\":true},\"FEntity\":[明细]}}";
                metails = metails.Replace("单据编号", FBillNo);
                metails = metails.Replace("销售组织", SaleOrgId);
                metails = metails.Replace("日期", FDate);
                metails = metails.Replace("单据类型", FBillTypeID);
                metails = metails.Replace("货主", OwnerIdHead);
                metails = metails.Replace("发货组织", StockOrgId);
                FCustomerID = CommonService.VKFCustomerID(ctx, FCustomerID);
                metails = metails.Replace("客户", FCustomerID);
                metails = metails.Replace("结算组织", SettleOrgId);
                metails = metails.Replace("价税合计", FBillAllAmount);
                metails = metails.Replace("明细", entity_post_data);

                object saveres = WebApiServiceCall.Save(ctx, "SAL_OUTSTOCK", metails);
                JObject res = JObject.FromObject(saveres);
                JObject res1 = JObject.Parse(res["Result"].ToString());
                JObject res2 = JObject.Parse(res1["ResponseStatus"].ToString());
                result["Result"] = true;
                result["Message"] = res["Result"].ToString();
            }
            catch (Exception e)
            {
                result["Result"] = false;
                result["Message"] = "数据格式不正确！" + e.Message;
            }
            return result.ToString();
        }

        internal string RETURNSTOCK(Context ctx, string strParams, JObject result)
        {
            JObject jParams = JObject.Parse(strParams);
            string dataCenterID = CommonService.GetJParamString(jParams, "dataCenterID");
            string userName = CommonService.GetJParamString(jParams, "userName");
            string passWord = CommonService.GetJParamString(jParams, "passWord");
            string FBillNo = CommonService.GetJParamString(jParams, "FBillNo");
            if (string.IsNullOrWhiteSpace(FBillNo))
            {
                result["Result"] = false;
                result["Message"] = "单据编号不能为空！";
                return result.ToString();
            }
            string FSettleOrgId = "";
            string FMaterialId = "";
            string FStockId = "";
            string FRealQty = "";
            string FOWNERID = "";
            string FBillAllAmount = "";
            string FAllAmount = "";
            string FThirdSrcEntryId = "";
            string FTaxPrice = "";
            string FSaleOrgId = CommonService.GetJParamString(jParams, "FSaleOrgId");
            string FDate = CommonService.GetJParamString(jParams, "FDate");
            string FBillTypeID = CommonService.GetJParamString(jParams, "FBillTypeID");
            string FStockOrgId = CommonService.GetJParamString(jParams, "FStockOrgId");
            string FRetcustId = CommonService.GetJParamString(jParams, "FRetcustId");
            string FOwnerIdHead = CommonService.GetJParamString(jParams, "FOwnerIdHead");
            string FThirdSrcId = CommonService.GetJParamString(jParams, "FThirdSrcId");
            string FThirdSrcBillNo = CommonService.GetJParamString(jParams, "FThirdSrcBillNo");
            string FThirdSystem = CommonService.GetJParamString(jParams, "FThirdSystem");
            string FNote = CommonService.GetJParamString(jParams, "FNote");


            string SaleOrgId = CommonService.VKGetBaseDataIdByValue(ctx, FSaleOrgId);
            if (SaleOrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FSaleOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string OwnerIdHead = CommonService.VKGetBaseDataIdByValue(ctx, FOwnerIdHead);
            if (OwnerIdHead == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FOwnerIdHead：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string StockOrgId = CommonService.VKGetBaseDataIdByValue(ctx, FStockOrgId);
            if (StockOrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FStockOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            //商品信息
            JArray FSubHeadEntity = JArray.Parse(jParams["FSubHeadEntity"].ToString());
            foreach (JObject List in FSubHeadEntity)
            {
                FSettleOrgId = List["FSettleOrgId"].ToString();
                FBillAllAmount = List["FBillAllAmount"].ToString();
            }
            string SettleOrgId = CommonService.VKGetBaseDataIdByValue(ctx, FSettleOrgId);
            if (SettleOrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FSettleOrgId】在系统中不存在！";
                return result.ToString();
            }
            string entity_post_data = "";
            string metail = "";
            string OWNERID = "";
            try
            {
                List<string> entitys = new List<string>();
                //物料
                JArray FEntity = JArray.Parse(jParams["FEntity"].ToString());
                foreach (JObject List in FEntity)
                {
                    metail = "{\"FRowType\":\"Standard\",\"FMaterialId\":{\"FNumber\":\"物料编码\"},\"FRealQty\":实退数量,\"FIsFree\":false,\"FEntryTaxRate\":13.00,\"FReturnType\":{\"FNumber\":\"THLX01_SYS\"},\"FOwnerTypeId\":\"BD_OwnerOrg\",\"FOwnerId\":{\"FNumber\":\"货主\"},\"FStockId\":{\"FNumber\":\"仓库\"},\"FStockstatusId\":{\"FNumber\":\"KCZT01_SYS\"},\"FDeliveryDate\":\"日期\",\"FTaxPrice\":含税单价,\"FIsOverLegalOrg\":false,\"FIsReturnCheck\":false,\"FSettleBySon\":false}";
                    FMaterialId = List["FMaterialID"].ToString();
                    FStockId = List["FStockId"].ToString();
                    FRealQty = List["FRealQty"].ToString();
                    FOWNERID = List["FOwnerId"].ToString();
                    FAllAmount = List["FAllAmount"].ToString();
                    FThirdSrcEntryId = List["FThirdSrcEntryId"].ToString();
                    FTaxPrice = List["FTaxPrice"].ToString();
                    OWNERID = CommonService.VKGetBaseDataIdByValue(ctx, FOWNERID);
                    if (OWNERID == "0")
                    {
                        result["Result"] = false;
                        result["Message"] = "参数【FOWNERID】在系统中不存在！";
                        return result.ToString();
                    }
                    FMaterialId = CommonService.VKFMaterialId(ctx, FMaterialId);
                    if (FMaterialId == "0")
                    {
                        result["Result"] = false;
                        result["Message"] = "商品不存在！";
                        return result.ToString();
                    }
                    FStockId = CommonService.VKFStockId(ctx, FStockId);
                    metail = metail.Replace("物料编码", FMaterialId);
                    metail = metail.Replace("仓库", FStockId);
                    metail = metail.Replace("实退数量", FRealQty);
                    metail = metail.Replace("货主", OWNERID);
                    metail = metail.Replace("含税单价", FTaxPrice);
                    metail = metail.Replace("日期", FDate);
                    entitys.Add(metail);
                }
                if (entitys.Count > 0)
                {
                    for (int j = 0; j < entitys.Count; j++)
                    {
                        entity_post_data = entity_post_data + entitys[j] + ",";
                    }
                }
                entity_post_data = entity_post_data.Remove(entity_post_data.Length - 1, 1);
                string metails = "{\"NeedUpDateFields\":[],\"NeedReturnFields\":[],\"IsDeleteEntry\":\"true\",\"SubSystemId\":\"\",\"IsVerifyBaseDataField\":\"false\",\"IsEntryBatchFill\":\"true\",\"ValidateFlag\":\"true\",\"NumberSearch\":\"true\",\"IsAutoAdjustField\":\"false\",\"InterationFlags\":\"\",\"IgnoreInterationFlag\":\"\",\"Model\":{\"FID\":0,\"FBillTypeID\":{\"FNUMBER\":\"单据类型\"},\"FBillNo\":\"单据编号\",\"FDate\":\"日期\",\"FSaleOrgId\":{\"FNumber\":\"销售组织\"},\"FRetcustId\":{\"FNumber\":\"退货客户\"},\"FTransferBizType\":{\"FNumber\":\"OverOrgSal\"},\"FStockOrgId\":{\"FNumber\":\"库存组织\"},\"FOwnerTypeIdHead\":\"BD_OwnerOrg\",\"FIsTotalServiceOrCost\":false,\"SubHeadEntity\":{\"FSettleCurrId\":{\"FNumber\":\"PRE001\"},\"FSettleOrgId\":{\"FNumber\":\"结算组织\"},\"FLocalCurrId\":{\"FNumber\":\"PRE001\"},\"FExchangeTypeId\":{\"FNumber\":\"HLTX01_SYS\"},\"FExchangeRate\":1.0},\"FEntity\":[ 明细]}}";
                metails = metails.Replace("单据编号", FBillNo);
                metails = metails.Replace("销售组织", SaleOrgId);
                metails = metails.Replace("日期", FDate);
                metails = metails.Replace("单据类型", FBillTypeID);
                metails = metails.Replace("库存组织", StockOrgId);
                FRetcustId = CommonService.VKFCustomerID(ctx, FRetcustId);
                metails = metails.Replace("退货客户", FRetcustId);
                metails = metails.Replace("结算组织", SettleOrgId);
                metails = metails.Replace("明细", entity_post_data);
                object saveres = WebApiServiceCall.Save(ctx, "SAL_RETURNSTOCK", metails);
                JObject res = JObject.FromObject(saveres);
                JObject res1 = JObject.Parse(res["Result"].ToString());
                JObject res2 = JObject.Parse(res1["ResponseStatus"].ToString());
                result["Result"] = true;
                result["Message"] = res["Result"].ToString();
            }
            catch (Exception e)
            {
                result["Result"] = false;
                result["Message"] = "数据格式不正确！" + e.Message;
            }
            return result.ToString();
        }

        internal string TransferDirect(Context ctx, string strParams, JObject result)
        {
            JObject jParams = JObject.Parse(strParams);
            string dataCenterID = CommonService.GetJParamString(jParams, "dataCenterID");
            string userName = CommonService.GetJParamString(jParams, "userName");
            string passWord = CommonService.GetJParamString(jParams, "passWord");
            string FBillNo = CommonService.GetJParamString(jParams, "FBillNo");
            if (string.IsNullOrWhiteSpace(FBillNo))
            {
                result["Result"] = false;
                result["Message"] = "单据编号不能为空！";
                return result.ToString();
            }
            string FMaterialId = "";
            string FSrcStockId = "";
            string FDestStockId = "";
            string FQty = "";
            string FOwnerTypeId = "";
            string FOwnerId = "";
            string FOwnerTypeOutId = "";
            string FOwnerOutId = "";
            string FKeeperTypeId = "";
            string FKeeperId = "";
            string FKeeperTypeOutId = "";
            string FKeeperOutId = "";
            string FNoteEntry = "";
            string FThirdSrcEntryId = "";
            string FStockOrgId = CommonService.GetJParamString(jParams, "FStockOrgId");
            string FDate = CommonService.GetJParamString(jParams, "FDate");
            string FBillTypeID = CommonService.GetJParamString(jParams, "FBillTypeID");
            string FOwnerTypeIdHead = CommonService.GetJParamString(jParams, "FOwnerTypeIdHead");
            string FOwnerIdHead = CommonService.GetJParamString(jParams, "FOwnerIdHead");
            string FTransferBizType = CommonService.GetJParamString(jParams, "FTransferBizType");
            string FStockOutOrgId = CommonService.GetJParamString(jParams, "FStockOutOrgId");
            string FOwnerTypeOutIdHead = CommonService.GetJParamString(jParams, "FOwnerTypeOutIdHead");
            string FOwnerOutIdHead = CommonService.GetJParamString(jParams, "FOwnerOutIdHead");
            string FTransferDirect = CommonService.GetJParamString(jParams, "FTransferDirect");
            string FThirdSrcId = CommonService.GetJParamString(jParams, "FThirdSrcId");
            string FThirdSrcBillNo = CommonService.GetJParamString(jParams, "FThirdSrcBillNo");
            string FThirdSystem = CommonService.GetJParamString(jParams, "FThirdSystem");
            string FNote = CommonService.GetJParamString(jParams, "FNote");

            string StockOrgId = "";
            string OwnerIdHead = "";
            string StockOutOrgId = "";
            string OwnerOutIdHead = "";
            string OwnerId = "";
            string OwnerOutId = "";
            string KeeperId = "";
            string KeeperOutId = "";
            string entity_post_data = "";
            string metail = "";
            StockOrgId = CommonService.VKGetBaseDataIdByValue(ctx, FStockOrgId);
            if (StockOrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FStockOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            OwnerIdHead = CommonService.VKGetBaseDataIdByValue(ctx, FOwnerIdHead);
            if (OwnerIdHead == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FOwnerIdHead：组织编码】在系统中不存在！";
                return result.ToString();
            }
            StockOutOrgId = CommonService.VKGetBaseDataIdByValue(ctx, FStockOutOrgId);
            if (StockOutOrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FStockOutOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            OwnerOutIdHead = CommonService.VKGetBaseDataIdByValue(ctx, FOwnerOutIdHead);
            if (OwnerOutIdHead == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FOwnerOutIdHead：组织编码】在系统中不存在！";
                return result.ToString();
            }
            try
            {
                List<string> entitys = new List<string>();
                //物料
                JArray FBillEntry = JArray.Parse(jParams["FBillEntry"].ToString());
                foreach (JObject List in FBillEntry)
                {
                    FMaterialId = List["FMaterialId"].ToString();
                    FSrcStockId = List["FSrcStockId"].ToString();
                    FDestStockId = List["FDestStockId"].ToString();
                    FQty = List["FQty"].ToString();
                    FOwnerTypeId = List["FOwnerTypeId"].ToString();
                    FOwnerId = List["FOwnerId"].ToString();
                    FOwnerTypeOutId = List["FOwnerTypeOutId"].ToString();
                    FOwnerOutId = List["FOwnerOutId"].ToString();
                    FKeeperTypeId = List["FKeeperTypeId"].ToString();
                    FKeeperId = List["FKeeperId"].ToString();
                    FKeeperTypeOutId = List["FKeeperTypeOutId"].ToString();
                    FKeeperOutId = List["FKeeperOutId"].ToString();
                    FNoteEntry = List["FNoteEntry"].ToString();
                    FThirdSrcEntryId = List["FThirdSrcEntryId"].ToString();
                    OwnerId = CommonService.VKGetBaseDataIdByValue(ctx, FOwnerId);
                    if (OwnerId == "0")
                    {
                        result["Result"] = false;
                        result["Message"] = "参数【FOwnerId：组织编码】在系统中不存在！";
                        return result.ToString();
                    }
                    OwnerOutId = CommonService.VKGetBaseDataIdByValue(ctx, FOwnerOutId);
                    if (OwnerOutId == "0")
                    {
                        result["Result"] = false;
                        result["Message"] = "参数【FOwnerOutId：组织编码】在系统中不存在！";
                        return result.ToString();
                    }
                    KeeperId = CommonService.VKGetBaseDataIdByValue(ctx, FKeeperId);
                    if (KeeperId == "0")
                    {
                        result["Result"] = false;
                        result["Message"] = "参数【FKeeperId：组织编码】在系统中不存在！";
                        return result.ToString();
                    }
                    KeeperOutId = CommonService.VKGetBaseDataIdByValue(ctx, FKeeperOutId);
                    if (KeeperOutId == "0")
                    {
                        result["Result"] = false;
                        result["Message"] = "参数【FKeeperOutId：组织编码】在系统中不存在！";
                        return result.ToString();
                    }
                    metail = "{\"FMaterialId\":{\"FNumber\":\"物料编码\"},\"FQty\":调拨数量,\"FSrcStockId\":{\"FNumber\":\"调出仓库\"},\"FDestStockId\":{\"FNumber\":\"调入仓库\"},\"FSrcStockStatusId\":{\"FNumber\":\"KCZT01_SYS\"},\"FDestStockStatusId\":{\"FNumber\":\"KCZT01_SYS\"},\"FBusinessDate\":\"日期\",\"FOwnerTypeOutId\":\"分录型\",\"FOwnerOutId\":{\"FNumber\":\"分录主\"},\"FOwnerTypeId\":\"货主类型\",\"FOwnerId\":{\"FNumber\":\"标记\"},\"FNoteEntry\":\"分录注\",\"FISFREE\":false,\"FKeeperTypeId\":\"调入保管者类型\",\"FKeeperId\":{\"FNumber\":\"调入保管者\"},\"FKeeperTypeOutId\":\"调出保管者类型\",\"FKeeperOutId\":{\"FNumber\":\"调出保管者\"},\"FTransReserveLink\":false,\"FCheckDelivery\":false}";
                    //分录
                    FMaterialId = CommonService.VKFMaterialId(ctx, FMaterialId);
                    if (FMaterialId == "0")
                    {
                        result["Result"] = false;
                        result["Message"] = "商品不存在！";
                        return result.ToString();
                    }
                    FDestStockId = CommonService.VKFStockId(ctx, FDestStockId);
                    FSrcStockId = CommonService.VKFStockId(ctx, FSrcStockId);
                    if (FTransferDirect == "RETURN")
                    {
                        metail = metail.Replace("物料编码", FMaterialId);
                        metail = metail.Replace("调出仓库", FDestStockId);
                        metail = metail.Replace("调入仓库", FSrcStockId);
                        metail = metail.Replace("日期", FDate);
                        metail = metail.Replace("调拨数量", FQty);
                        metail = metail.Replace("货主类型", FOwnerTypeId);
                        metail = metail.Replace("标记", OwnerOutId);
                        metail = metail.Replace("分录型", FOwnerTypeOutId);
                        metail = metail.Replace("分录主", OwnerId);
                        metail = metail.Replace("调入保管者类型", FKeeperTypeId);
                        metail = metail.Replace("调入保管者", KeeperOutId);
                        metail = metail.Replace("调出保管者类型", FKeeperTypeOutId);
                        metail = metail.Replace("调出保管者", KeeperId);
                        metail = metail.Replace("分录注", FNoteEntry);
                        //metail = metail.Replace("第三方单据分录ID", FThirdSrcEntryId);
                    }
                    else
                    {
                        metail = metail.Replace("物料编码", FMaterialId);
                        metail = metail.Replace("调出仓库", FSrcStockId);
                        metail = metail.Replace("调入仓库", FDestStockId);
                        metail = metail.Replace("日期", FDate);
                        metail = metail.Replace("调拨数量", FQty);
                        metail = metail.Replace("货主类型", FOwnerTypeId);
                        metail = metail.Replace("标记", OwnerId);
                        metail = metail.Replace("分录型", FOwnerTypeOutId);
                        metail = metail.Replace("分录主", OwnerOutId);
                        metail = metail.Replace("调入保管者类型", FKeeperTypeId);
                        metail = metail.Replace("调入保管者", KeeperId);
                        metail = metail.Replace("调出保管者类型", FKeeperTypeOutId);
                        metail = metail.Replace("调出保管者", KeeperOutId);
                        metail = metail.Replace("分录注", FNoteEntry);
                        //metail = metail.Replace("第三方单据分录ID", FThirdSrcEntryId);
                    }
                    entitys.Add(metail);
                }
                if (entitys.Count > 0)
                {
                    for (int j = 0; j < entitys.Count; j++)
                    {
                        entity_post_data = entity_post_data + entitys[j] + ",";
                    }
                }
                entity_post_data = entity_post_data.Remove(entity_post_data.Length - 1, 1);
                string metails = "{\"NeedUpDateFields\":[],\"NeedReturnFields\":[],\"IsDeleteEntry\":\"true\",\"SubSystemId\":\"\",\"IsVerifyBaseDataField\":\"false\",\"IsEntryBatchFill\":\"true\",\"ValidateFlag\":\"true\",\"NumberSearch\":\"true\",\"IsAutoAdjustField\":\"false\",\"InterationFlags\":\"\",\"IgnoreInterationFlag\":\"\",\"Model\":{\"FID\":0,\"FBillNo\":\"单据编号\",\"FBillTypeID\":{\"FNUMBER\":\"单据类型\"},\"FBizType\":\"NORMAL\",\"FTransferDirect\":\"调拨方向\",\"FTransferBizType\":\"调拨类型\",\"FSettleOrgId\":{\"FNumber\":\"调出库存组织\"},\"FSaleOrgId\":{\"FNumber\":\"调出库存组织\"},\"FStockOutOrgId\":{\"FNumber\":\"调出库存组织\"},\"FOwnerTypeOutIdHead\":\"调出货主类型\",\"FOwnerOutIdHead\":{\"FNumber\":\"调出货主\"},\"FStockOrgId\":{\"FNumber\":\"调入库存组织\"},\"FIsIncludedTax\":true,\"FIsPriceExcludeTax\":true,\"FExchangeTypeId\":{\"FNUMBER\":\"HLTX01_SYS\"},\"FOwnerTypeIdHead\":\"调入货主类型\",\"FSETTLECURRID\":{\"FNUMBER\":\"PRE001\"},\"FExchangeRate\":1.0,\"FOwnerIdHead\":{\"FNumber\":\"调入货主\"},\"FDate\":\"日期\",\"FNote\":\"备注\",\"FBaseCurrId\":{\"FNumber\":\"PRE001\"},\"FBillEntry\":[明细]}}";
                if (StockOrgId == StockOutOrgId)
                {
                    FTransferBizType = "InnerOrgTransfer";
                }
                else
                {
                    FTransferBizType = "OverOrgTransfer";
                }
                if (FTransferDirect == "RETURN")
                {
                    metails = metails.Replace("单据编号", FBillNo);
                    metails = metails.Replace("调入库存组织", StockOutOrgId);
                    metails = metails.Replace("日期", FDate);
                    metails = metails.Replace("单据类型", FBillTypeID);
                    metails = metails.Replace("调入货主类型", FOwnerTypeIdHead);
                    metails = metails.Replace("调入货主", OwnerOutIdHead);
                    metails = metails.Replace("调拨类型", FTransferBizType);
                    metails = metails.Replace("备注", FNote);
                    metails = metails.Replace("调出库存组织", StockOrgId);
                    metails = metails.Replace("调出货主类型", FOwnerTypeOutIdHead);
                    metails = metails.Replace("调出货主", OwnerIdHead);
                    metails = metails.Replace("调拨方向", FTransferDirect);
                    metails = metails.Replace("明细", entity_post_data);
                }
                else
                {
                    metails = metails.Replace("单据编号", FBillNo);
                    metails = metails.Replace("调入库存组织", StockOrgId);
                    metails = metails.Replace("日期", FDate);
                    metails = metails.Replace("单据类型", FBillTypeID);
                    metails = metails.Replace("调入货主类型", FOwnerTypeIdHead);
                    metails = metails.Replace("调入货主", OwnerIdHead);
                    metails = metails.Replace("调拨类型", FTransferBizType);
                    metails = metails.Replace("备注", FNote);
                    metails = metails.Replace("调出库存组织", StockOutOrgId);
                    metails = metails.Replace("调出货主类型", FOwnerTypeOutIdHead);
                    metails = metails.Replace("调出货主", OwnerOutIdHead);
                    metails = metails.Replace("调拨方向", FTransferDirect);
                    metails = metails.Replace("明细", entity_post_data);
                }

                object saveres = WebApiServiceCall.Save(ctx, "STK_TransferDirect", metails);
                JObject res = JObject.FromObject(saveres);
                JObject res1 = JObject.Parse(res["Result"].ToString());
                JObject res2 = JObject.Parse(res1["ResponseStatus"].ToString());
                result["Result"] = true;
                result["Message"] = res["Result"].ToString();
            }
            catch (Exception e)
            {
                result["Result"] = false;
                result["Message"] = "数据格式不正确！" + e.Message;
            }
            return result.ToString();
        }

        internal string MisDelivery(Context ctx, string strParams, JObject result)
        {
           
            JObject jParams = JObject.Parse(strParams);
            string dataCenterID = CommonService.GetJParamString(jParams, "dataCenterID");
            string userName = CommonService.GetJParamString(jParams, "userName");
            string passWord = CommonService.GetJParamString(jParams, "passWord");
            string FBillNo = CommonService.GetJParamString(jParams, "FBillNo");
            if (string.IsNullOrWhiteSpace(FBillNo))
            {
                result["Result"] = false;
                result["Message"] = "单据编号不能为空！";
                return result.ToString();
            }
            string FMaterialId = "";
            string FStockId = "";
            string FQty = "";
            string FThirdSrcEntryId = "";
            string FStockOrgId = CommonService.GetJParamString(jParams, "FStockOrgId");
            string FDate = CommonService.GetJParamString(jParams, "FDate");
            string FBillTypeID = CommonService.GetJParamString(jParams, "FBillTypeID");
            string FOwnerIdHead = CommonService.GetJParamString(jParams, "FOwnerIdHead");
            string FCustId = CommonService.GetJParamString(jParams, "FCustId");
            string FPickerId = CommonService.GetJParamString(jParams, "FPickerId");
            string FThirdSrcId = CommonService.GetJParamString(jParams, "FThirdSrcId");
            string FThirdSrcBillNo = CommonService.GetJParamString(jParams, "FThirdSrcBillNo");
            string FThirdSystem = CommonService.GetJParamString(jParams, "FThirdSystem");
            string FNote = CommonService.GetJParamString(jParams, "FNote");

            string StockOrgId = CommonService.VKGetBaseDataIdByValue(ctx, FStockOrgId);
            if (StockOrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FStockOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string OwnerIdHead = CommonService.VKGetBaseDataIdByValue(ctx, FOwnerIdHead);
            if (OwnerIdHead == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FOwnerIdHead：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string metail = "";
            string entity_post_data = "";
            try
            {
                List<string> entitys = new List<string>();
                //物料
                JArray FBillEntry = JArray.Parse(jParams["FEntity"].ToString());
                foreach (JObject List in FBillEntry)
                {

                    FMaterialId = List["FMaterialId"].ToString();
                    FStockId = List["FStockId"].ToString();
                    FQty = List["FQty"].ToString();
                    FThirdSrcEntryId = List["FThirdSrcEntryId"].ToString();
                    metail = "{\"FMaterialId\":{\"FNumber\":\"物料编码\"},\"FQty\":实发数量,\"FStockId\":{\"FNumber\":\"发货仓库\"},\"FEntryNote\":\"\",\"FStockStatusId\":{\"FNumber\":\"KCZT01_SYS\"}}";//,\"FOwnerTypeId\":\"BD_OwnerOrg\",\"FOwnerId\":{\"FNumber\":\"货主\"},\"FKeeperTypeId\":\"BD_KeeperOrg\",\"FDistribution\":false,\"FKeeperId\":{\"FNumber\":\"货主\"}

                    FMaterialId = CommonService.VKFMaterialId(ctx, FMaterialId);
                    if (FMaterialId == "0")
                    {
                        result["Result"] = false;
                        result["Message"] = "商品不存在！";
                        return result.ToString();
                    }
                    FStockId = CommonService.VKFStockId(ctx, FStockId);
                    //分录
                    metail = metail.Replace("物料编码", FMaterialId);
                    metail = metail.Replace("发货仓库", FStockId);
                    metail = metail.Replace("第三方源单分录编码", FThirdSrcEntryId);
                    metail = metail.Replace("实发数量", FQty);
                    //metail = metail.Replace("第三方单据分录ID", FThirdSrcEntryId);
                    entitys.Add(metail);
                }
                if (entitys.Count > 0)
                {
                    for (int j = 0; j < entitys.Count; j++)
                    {
                        entity_post_data = entity_post_data + entitys[j] + ",";
                    }
                }
                entity_post_data = entity_post_data.Remove(entity_post_data.Length - 1, 1);
                string metails = "{\"NeedUpDateFields\":[],\"NeedReturnFields\":[],\"IsDeleteEntry\":\"true\",\"SubSystemId\":\"\",\"IsVerifyBaseDataField\":\"false\",\"IsEntryBatchFill\":\"true\",\"ValidateFlag\":\"true\",\"NumberSearch\":\"true\",\"IsAutoAdjustField\":\"false\",\"InterationFlags\":\"\",\"IgnoreInterationFlag\":\"\",\"Model\":{\"FID\":0,\"FBillNo\":\"单据编号\",\"FBillTypeID\":{\"FNUMBER\":\"单据类型\"},\"FStockOrgId\":{\"FNumber\":\"调入库存组织\"},\"FPickOrgId\":{\"FNumber\":\"调入库存组织\"},\"FStockDirect\":\"GENERAL\",\"FDate\":\"日期\",\"FCustId\":{\"FNumber\":\"客户\"},\"FDeptId\":{\"FNumber\":\"BM000001\"},\"FPickerId\":{\"FStaffNumber\":\"领料人\"},\"FOwnerTypeIdHead\":\"BD_OwnerOrg\",\"FOwnerIdHead\":{\"FNumber\":\"货主\"},\"FNote\":\"备注\",\"FBaseCurrId\":{\"FNumber\":\"PRE001\"},\"FEntity\":[明细]}}";
                metails = metails.Replace("单据编号", FBillNo);
                metails = metails.Replace("调入库存组织", StockOrgId);
                metails = metails.Replace("日期", FDate);
                metails = metails.Replace("单据类型", FBillTypeID);
                metails = metails.Replace("货主", OwnerIdHead);
                FCustId = CommonService.VKFCustomerID(ctx, FCustId);
                metails = metails.Replace("客户", FCustId);
                metails = metails.Replace("备注", FNote);
                metails = metails.Replace("领料人", FPickerId);
                metails = metails.Replace("内码", FThirdSrcId);
                metails = metails.Replace("第三方分录", FThirdSrcBillNo);
                metails = metails.Replace("系统", FThirdSystem);
                metails = metails.Replace("明细", entity_post_data);

                object saveres = WebApiServiceCall.Save(ctx, "STK_MisDelivery", metails);
                JObject res = JObject.FromObject(saveres);
                JObject res1 = JObject.Parse(res["Result"].ToString());
                JObject res2 = JObject.Parse(res1["ResponseStatus"].ToString());
                result["Result"] = true;
                result["Message"] = res["Result"].ToString();
            }
            catch (Exception e)
            {
                result["Result"] = false;
                result["Message"] = "数据格式不正确！" + e.Message;
            }
            return result.ToString();
        }

        internal string MISCELLANEOUS(Context ctx, string strParams, JObject result)
        {
            JObject jParams = JObject.Parse(strParams);
            string dataCenterID = CommonService.GetJParamString(jParams, "dataCenterID");
            string userName = CommonService.GetJParamString(jParams, "userName");
            string passWord = CommonService.GetJParamString(jParams, "passWord");
            string FBillNo = CommonService.GetJParamString(jParams, "FBillNo");
            if (string.IsNullOrWhiteSpace(FBillNo))
            {
                result["Result"] = false;
                result["Message"] = "单据编号不能为空！";
                return result.ToString();
            }
            string FMaterialId = "";
            string FStockId = "";
            string FQty = "";
            string FThirdSrcEntryId = "";
            string FEntryNote = "";
            string FStockOrgId = CommonService.GetJParamString(jParams, "FStockOrgId");
            string FDate = CommonService.GetJParamString(jParams, "FDate");
            string FBillTypeID = CommonService.GetJParamString(jParams, "FBillTypeID");
            string FOwnerIdHead = CommonService.GetJParamString(jParams, "FOwnerIdHead");

            string FSUPPLIERID = CommonService.GetJParamString(jParams, "FSUPPLIERID");
            if(FSUPPLIERID != "VKSC001")
            {
                //FSUPPLIERID = CommonService.VKGetBaseDataIdByValue(ctx, FSUPPLIERID);
                //if (FSUPPLIERID == "0")
                //{
                //    result["Result"] = false;
                //    result["Message"] = "参数【FSUPPLIERID：账户编码】在系统中不存在！";
                //    return result.ToString();
                //}
            }
            string FACCEPTANCE = CommonService.GetJParamString(jParams, "FACCEPTANCE");
            string FThirdSrcId = CommonService.GetJParamString(jParams, "FThirdSrcId");
            string FThirdSrcBillNo = CommonService.GetJParamString(jParams, "FThirdSrcBillNo");
            string FThirdSystem = CommonService.GetJParamString(jParams, "FThirdSystem");
            string FNote = CommonService.GetJParamString(jParams, "FNote");

            string StockOrgId = CommonService.VKGetBaseDataIdByValue(ctx, FStockOrgId);
            if (StockOrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FStockOrgId：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string OwnerIdHead = CommonService.VKGetBaseDataIdByValue(ctx, FOwnerIdHead);
            if (OwnerIdHead == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FOwnerIdHead：组织编码】在系统中不存在！";
                return result.ToString();
            }
            string entity_post_data = "";
            string metail = "";


            try
            {
                List<string> entitys = new List<string>();
                //物料
                JArray FBillEntry = JArray.Parse(jParams["FEntity"].ToString());
                foreach (JObject List in FBillEntry)
                {
                    metail = "{\"FMATERIALID\":{\"FNumber\":\"物料编码\"},\"FSTOCKID\":{\"FNumber\":\"收货仓库\"},\"FSTOCKSTATUSID\":{\"FNumber\":\"KCZT01_SYS\"},\"FQty\":实发数量,\"FEntryNote\":\"分录注\"}";//,\"FOWNERTYPEID\":\"BD_OwnerOrg\",\"FOWNERID\":{\"FNumber\":\"货主\"},\"FKEEPERTYPEID\":\"BD_KeeperOrg\",\"FKEEPERID\":{\"FNumber\":\"货主\"}
                    FMaterialId = List["FMaterialId"].ToString();
                    FStockId = List["FStockId"].ToString();
                    FQty = List["FQty"].ToString();
                    FEntryNote = List["FEntryNote"].ToString();
                    FThirdSrcEntryId = List["FThirdSrcEntryId"].ToString();
                    //分录
                    FMaterialId = CommonService.VKFMaterialId(ctx, FMaterialId);
                    if (FMaterialId == "0")
                    {
                        result["Result"] = false;
                        result["Message"] = "商品不存在！";
                        return result.ToString();
                    }
                    FStockId = CommonService.VKFStockId(ctx, FStockId);
                    metail = metail.Replace("物料编码", FMaterialId);
                    metail = metail.Replace("收货仓库", FStockId);
                    metail = metail.Replace("第三方源单分录编码", FThirdSrcEntryId);
                    metail = metail.Replace("实发数量", FQty);
                    metail = metail.Replace("分录注", FEntryNote);
                    //metail = metail.Replace("第三方单据分录ID", FThirdSrcEntryId);
                    entitys.Add(metail);
                }
                if (entitys.Count > 0)
                {
                    for (int j = 0; j < entitys.Count; j++)
                    {
                        entity_post_data = entity_post_data + entitys[j] + ",";
                    }
                }
                entity_post_data = entity_post_data.Remove(entity_post_data.Length - 1, 1);
                string metails = "{\"NeedUpDateFields\":[],\"NeedReturnFields\":[],\"IsDeleteEntry\":\"true\",\"SubSystemId\":\"\",\"IsVerifyBaseDataField\":\"false\",\"IsEntryBatchFill\":\"true\",\"ValidateFlag\":\"true\",\"NumberSearch\":\"true\",\"IsAutoAdjustField\":\"false\",\"InterationFlags\":\"\",\"IgnoreInterationFlag\":\"\",\"Model\":{\"FID\":0,\"FBillNo\":\"单据编号\",\"FBillTypeID\":{\"FNUMBER\":\"单据类型\"},\"FStockOrgId\":{\"FNumber\":\"调入库存组织\"},\"FStockDirect\":\"GENERAL\",\"FDate\":\"日期\",\"FSUPPLIERID\":{\"FNumber\":\"供应商\"},\"FACCEPTANCE\":{\"FStaffNumber\":\"验收员\"},\"FOwnerTypeIdHead\":\"BD_OwnerOrg\",\"FOwnerIdHead\":{\"FNumber\":\"货主\"},\"FNOTE\":\"备注\",\"FBaseCurrId\":{\"FNumber\":\"PRE001\"},\"FEntity\":[明细]}}";
                metails = metails.Replace("单据编号", FBillNo);
                metails = metails.Replace("调入库存组织", StockOrgId);
                metails = metails.Replace("日期", FDate);
                metails = metails.Replace("单据类型", FBillTypeID);
                metails = metails.Replace("货主", OwnerIdHead);
                FSUPPLIERID = CommonService.VKFSupplierId(ctx, FSUPPLIERID);
                metails = metails.Replace("供应商", FSUPPLIERID);
                metails = metails.Replace("备注", FNote);
                metails = metails.Replace("验收员", FACCEPTANCE);
                metails = metails.Replace("内码", FThirdSrcId);
                metails = metails.Replace("第三方分录", FThirdSrcBillNo);
                metails = metails.Replace("系统", FThirdSystem);
                metails = metails.Replace("明细", entity_post_data);


                object saveres = WebApiServiceCall.Save(ctx, "STK_MISCELLANEOUS", metails);
                JObject res = JObject.FromObject(saveres);
                JObject res1 = JObject.Parse(res["Result"].ToString());
                JObject res2 = JObject.Parse(res1["ResponseStatus"].ToString());
                result["Result"] = true;
                result["Message"] = res["Result"].ToString();
            }
            catch (Exception e)
            {
                result["Result"] = false;
                result["Message"] = "数据格式不正确！" + e.Message;
            }
            return result.ToString();
        }

        internal string StockCountGain(Context ctx, string strParams, JObject result)
        {
            JObject jParams = JObject.Parse(strParams);
            string dataCenterID = CommonService.GetJParamString(jParams, "dataCenterID");
            string userName = CommonService.GetJParamString(jParams, "userName");
            string passWord = CommonService.GetJParamString(jParams, "passWord");
            string FBillNo = CommonService.GetJParamString(jParams, "FBillNo");
            if (string.IsNullOrWhiteSpace(FBillNo))
            {
                result["Result"] = false;
                result["Message"] = "单据编号不能为空！";
                return result.ToString();
            }
            string FMaterialId = "";
            string FStockId = "";
            long  FGainQty = 0L;
            string FThirdSrcEntryId = "";
            string FOwnerId = "";
            string FOwnerTypeId = "";
            string FKeeperTypeId = "";
            string FKeeperId = "";
            string FNote = "";
            string FBusinessDate = "";
            long FBASEQTY = 0L;
            string FNUMBER = "";
            long FBASEQTYS = 0L;
            string FBASEQTYST = "";
            string FStockOrgId = CommonService.GetJParamString(jParams, "FStockOrgId");
            string FDate = CommonService.GetJParamString(jParams, "FDate");
            string FBillTypeID = CommonService.GetJParamString(jParams, "FBillTypeID");
            string FOwnerIdHead = CommonService.GetJParamString(jParams, "FOwnerIdHead");
            string FNoteHead = CommonService.GetJParamString(jParams, "FNoteHead");
            string FThirdSrcId = CommonService.GetJParamString(jParams, "FThirdSrcId");
            string FThirdSrcBillNo = CommonService.GetJParamString(jParams, "FThirdSrcBillNo");
            string FThirdSystem = CommonService.GetJParamString(jParams, "FThirdSystem");

            string StockOrgId = CommonService.VKGetBaseDataIdByValue(ctx, FStockOrgId);
            if (StockOrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FStockOrgId：编码】在系统中不存在！";
                return result.ToString();
            }
            string OwnerIdHead = CommonService.VKGetBaseDataIdByValue(ctx, FOwnerIdHead);
            if (OwnerIdHead == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FOwnerIdHead：编码】在系统中不存在！";
                return result.ToString();
            }
            string OwnerId = "";
            string KeeperId = "";
            string metail = "";
            string entity_post_data = "";



            try
            {
                List<string> entitys = new List<string>();
                //物料
                JArray FBillEntry = JArray.Parse(jParams["FBillEntry"].ToString());
                foreach (JObject List in FBillEntry)
                {
                    FMaterialId = List["FMaterialId"].ToString();
                    FStockId = List["FStockId"].ToString();
                    FGainQty = Convert.ToInt64(List["FGainQty"].ToString());
                    FOwnerId = List["FOwnerId"].ToString();
                    FOwnerTypeId = List["FOwnerTypeId"].ToString();
                    FKeeperTypeId = List["FKeeperTypeId"].ToString();
                    FKeeperId = List["FKeeperId"].ToString();
                    FNote = List["FNote"].ToString();
                    FBusinessDate = List["FBusinessDate"].ToString();
                    FThirdSrcEntryId = List["FThirdSrcEntryId"].ToString();
                    string str = string.Format(@"select  t1.FNUMBER as FNUMBER,FBASEQTY from  T_STK_INVENTORY t 
                        inner join T_BD_UNIT t1 on t1.FUNITID = t.FBASEUNITID
                        inner join T_BD_STOCK t2 on t2.FSTOCKID = t.FSTOCKID 
                        inner join T_BD_MATERIAL T3 ON T3.FMATERIALID  = T.FMATERIALID 
                        where T3.FNUMBER = '{0}' AND T2.FNUMBER = '{1}'", FMaterialId, FStockId);
                    var Datas = DBUtils.ExecuteDynamicObject(ctx, str);
                    if (Datas != null && Datas.Count > 0)
                    {
                        FBASEQTY = Convert.ToInt64(Datas.First()["FBASEQTY"]);
                        FNUMBER = Convert.ToString(Datas.First()["FNUMBER"]);

                    }
                    else
                    {
                        FBASEQTY = 0;
                    }
                    FBASEQTYS = FBASEQTY + FGainQty;
                    FBASEQTYST = Convert.ToString(FBASEQTYS);
                    OwnerId = CommonService.VKGetBaseDataIdByValue(ctx, FOwnerId);
                    if (OwnerId == "0")
                    {
                        result["Result"] = false;
                        result["Message"] = "参数【FOwnerId：编码】在系统中不存在！";
                        return result.ToString();
                    }
                    KeeperId = CommonService.VKGetBaseDataIdByValue(ctx, FKeeperId);
                    if (KeeperId == "0")
                    {
                        result["Result"] = false;
                        result["Message"] = "参数【FKeeperId：编码】在系统中不存在！";
                        return result.ToString();
                    }
                    metail = "{\"FMaterialId\":{\"FNumber\":\"物料编码\"},\"FCountQty\":盘盈数量,\"FStockId\":{\"FNumber\":\"仓库\"},\"FBusinessDate\":\"入库日\",\"FOwnerTypeId\":\"货类型\",\"FOwnerid\":{\"FNumber\":\"分主\"},\"Fnote\":\"分录注\",\"FStockStatusId\":{\"FNumber\":\"KCZT01_SYS\"},\"FKeeperTypeId\":\"保管者类型\",\"FKeeperId\":{\"FNumber\":\"保管者\"}}";
                    //分录
                    FMaterialId = CommonService.VKFMaterialId(ctx, FMaterialId);
                    if (FMaterialId == "0")
                    {
                        result["Result"] = false;
                        result["Message"] = "商品不存在！";
                        return result.ToString();
                    }
                    FStockId = CommonService.VKFStockId(ctx, FStockId);
                    metail = metail.Replace("物料编码", FMaterialId);
                    metail = metail.Replace("仓库", FStockId);
                    metail = metail.Replace("第三方源单分录编码", FThirdSrcEntryId);
                    metail = metail.Replace("盘盈数量", FBASEQTYST);
                    metail = metail.Replace("分录注", FNote);
                    metail = metail.Replace("货类型", FOwnerTypeId);
                    metail = metail.Replace("分主", OwnerId);
                    metail = metail.Replace("保管者类型", FKeeperTypeId);
                    metail = metail.Replace("保管者", KeeperId);
                    metail = metail.Replace("入库日", FBusinessDate);
                    entitys.Add(metail);
                }
                if (entitys.Count > 0)
                {
                    for (int j = 0; j < entitys.Count; j++)
                    {
                        entity_post_data = entity_post_data + entitys[j] + ",";
                    }
                }
                entity_post_data = entity_post_data.Remove(entity_post_data.Length - 1, 1);
                string metails = "{\"NeedUpDateFields\":[],\"NeedReturnFields\":[],\"IsDeleteEntry\":\"true\",\"SubSystemId\":\"\",\"IsVerifyBaseDataField\":\"false\",\"IsEntryBatchFill\":\"true\",\"ValidateFlag\":\"true\",\"NumberSearch\":\"true\",\"IsAutoAdjustField\":\"false\",\"InterationFlags\":\"\",\"IgnoreInterationFlag\":\"\",\"Model\":{\"FID\":0,\"FBillNo\":\"单据编号\",\"FBillTypeID\":{\"FNUMBER\":\"单据类型\"},\"FStockOrgId\":{\"FNumber\":\"库存组织\"},\"FOwnerTypeIdHead\":\"BD_OwnerOrg\",\"FOwnerIdHead\":{\"FNumber\":\"货主\"},\"FDate\":\"日期\",\"FNoteHead\":\"备注\",\"FBillEntry\":[明细]}}";
                metails = metails.Replace("单据编号", FBillNo);
                metails = metails.Replace("库存组织", StockOrgId);
                metails = metails.Replace("日期", FDate);
                metails = metails.Replace("单据类型", FBillTypeID);
                metails = metails.Replace("货主", OwnerIdHead);
                metails = metails.Replace("备注", FNoteHead);
                metails = metails.Replace("内码", FThirdSrcId);
                metails = metails.Replace("第三方分录", FThirdSrcBillNo);
                metails = metails.Replace("系统", FThirdSystem);
                metails = metails.Replace("明细", entity_post_data);

                object saveres = WebApiServiceCall.Save(ctx, "STK_StockCountGain", metails);
                JObject res = JObject.FromObject(saveres);
                JObject res1 = JObject.Parse(res["Result"].ToString());
                JObject res2 = JObject.Parse(res1["ResponseStatus"].ToString());
                result["Result"] = true;
                result["Message"] = res["Result"].ToString();
            }
            catch (Exception e)
            {
                result["Result"] = false;
                result["Message"] = "数据格式不正确！" + e.Message;
            }
            return result.ToString();
        }

        internal string StockCountLoss(Context ctx, string strParams, JObject result)
        {
            JObject jParams = JObject.Parse(strParams);
            string dataCenterID = CommonService.GetJParamString(jParams, "dataCenterID");
            string userName = CommonService.GetJParamString(jParams, "userName");
            string passWord = CommonService.GetJParamString(jParams, "passWord");
            string FBillNo = CommonService.GetJParamString(jParams, "FBillNo");
            if (string.IsNullOrWhiteSpace(FBillNo))
            {
                result["Result"] = false;
                result["Message"] = "单据编号不能为空！";
                return result.ToString();
            }
            string FMaterialId = "";
            string FStockId = "";
            long FLossQty = 0L;
            string FThirdSrcEntryId = "";
            string FOwnerId = "";
            string FOwnerTypeId = "";
            string FKeeperTypeId = "";
            string FKeeperId = "";
            string FNote = "";
            long FBASEQTY = 0L;
            string FNUMBER = "";
            long FBASEQTYS = 0L;
            string FBASEQTYST = "";
            string FStockOrgId = CommonService.GetJParamString(jParams, "FStockOrgId");
            string FDate = CommonService.GetJParamString(jParams, "FDate");
            string FBillTypeID = CommonService.GetJParamString(jParams, "FBillTypeID");
            string FOwnerIdHead = CommonService.GetJParamString(jParams, "FOwnerIdHead");
            string FNoteHead = CommonService.GetJParamString(jParams, "FNoteHead");
            string FThirdSrcId = CommonService.GetJParamString(jParams, "FThirdSrcId");
            string FThirdSrcBillNo = CommonService.GetJParamString(jParams, "FThirdSrcBillNo");
            string FThirdSystem = CommonService.GetJParamString(jParams, "FThirdSystem");

            string StockOrgId = CommonService.VKGetBaseDataIdByValue(ctx, FStockOrgId);
            if (StockOrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FStockOrgId：编码】在系统中不存在！";
                return result.ToString();
            }
            string OwnerIdHead = CommonService.VKGetBaseDataIdByValue(ctx, FOwnerIdHead);
            if (OwnerIdHead == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FOwnerIdHead：编码】在系统中不存在！";
                return result.ToString();
            }
            string OwnerId = "";
            string KeeperId = "";
            string entity_post_data = "";
            string metail = "";

            //物料
            try
            {

                List<string> entitys = new List<string>();
                JArray FBillEntry = JArray.Parse(jParams["FBillEntry"].ToString());
                foreach (JObject List in FBillEntry)
                {

                    FMaterialId = List["FMaterialId"].ToString();
                    FStockId = List["FStockId"].ToString();
                    FLossQty = Convert.ToInt64(List["FLossQty"].ToString());
                    FOwnerId = List["FOwnerId"].ToString();
                    FOwnerTypeId = List["FOwnerTypeId"].ToString();
                    FKeeperTypeId = List["FKeeperTypeId"].ToString();
                    FKeeperId = List["FKeeperId"].ToString();
                    FNote = List["FNote"].ToString();
                    FThirdSrcEntryId = List["FThirdSrcEntryId"].ToString();
                    string str = string.Format(@"select  t1.FNUMBER as FNUMBER,FBASEQTY from  T_STK_INVENTORY t 
                        inner join T_BD_UNIT t1 on t1.FUNITID = t.FBASEUNITID
                        inner join T_BD_STOCK t2 on t2.FSTOCKID = t.FSTOCKID 
                        inner join T_BD_MATERIAL T3 ON T3.FMATERIALID  = T.FMATERIALID 
                        where T3.FNUMBER = '{0}' AND T2.FNUMBER = '{1}'", FMaterialId, FStockId);
                    var Datas = DBUtils.ExecuteDynamicObject(ctx, str);
                    if (Datas != null && Datas.Count > 0)
                    {
                        FBASEQTY = Convert.ToInt64(Datas.First()["FBASEQTY"]);
                        FNUMBER = Convert.ToString(Datas.First()["FNUMBER"]);

                    }
                    else
                    {
                        FBASEQTY = 0;
                    }
                    FBASEQTYS = FBASEQTY - FLossQty;
                    FBASEQTYST = Convert.ToString(FBASEQTYS);
                    OwnerId = CommonService.VKGetBaseDataIdByValue(ctx, FOwnerId);
                    if (OwnerId == "0")
                    {
                        result["Result"] = false;
                        result["Message"] = "参数【FOwnerId：编码】在系统中不存在！";
                        return result.ToString();
                    }
                    KeeperId = CommonService.VKGetBaseDataIdByValue(ctx, FKeeperId);
                    if (KeeperId == "0")
                    {
                        result["Result"] = false;
                        result["Message"] = "参数【FKeeperId：编码】在系统中不存在！";
                        return result.ToString();
                    }
                    metail = "{\"FMaterialId\":{\"FNumber\":\"物料编码\"},\"FCountQty\":盘亏数量,\"FStockId\":{\"FNumber\":\"仓库\"},\"FStockStatusId\":{\"FNumber\":\"KCZT01_SYS\"},\"FOwnerTypeId\":\"货类型\",\"FOwnerid\":{\"FNumber\":\"分主\"},\"Fnote\":\"分录注\",\"FKeeperTypeId\":\"保管者类型\",\"FKeeperId\":{\"FNumber\":\"保管者\"}}";
                    FMaterialId = CommonService.VKFMaterialId(ctx, FMaterialId);
                    if (FMaterialId == "0")
                    {
                        result["Result"] = false;
                        result["Message"] = "商品不存在！";
                        return result.ToString();
                    }
                    FStockId = CommonService.VKFStockId(ctx, FStockId);
                    metail = metail.Replace("物料编码", FMaterialId);
                    metail = metail.Replace("仓库", FStockId);
                    metail = metail.Replace("第三方源单分录编码", FThirdSrcEntryId);
                    metail = metail.Replace("盘亏数量", FBASEQTYST);
                    metail = metail.Replace("分录注", FNote);
                    metail = metail.Replace("货类型", FOwnerTypeId);
                    metail = metail.Replace("分主", OwnerId);
                    metail = metail.Replace("保管者类型", FKeeperTypeId);
                    metail = metail.Replace("保管者", KeeperId);
                    entitys.Add(metail);

                }
                if (entitys.Count > 0)
                {
                    for (int j = 0; j < entitys.Count; j++)
                    {
                        entity_post_data = entity_post_data + entitys[j] + ",";
                    }
                }
                entity_post_data = entity_post_data.Remove(entity_post_data.Length - 1, 1);
                string metails = "{\"NeedUpDateFields\":[],\"NeedReturnFields\":[],\"IsDeleteEntry\":\"true\",\"SubSystemId\":\"\",\"IsVerifyBaseDataField\":\"false\",\"IsEntryBatchFill\":\"true\",\"ValidateFlag\":\"true\",\"NumberSearch\":\"true\",\"IsAutoAdjustField\":\"false\",\"InterationFlags\":\"\",\"IgnoreInterationFlag\":\"\",\"Model\":{\"FID\":0,\"FBillNo\":\"单据编号\",\"FBillTypeID\":{\"FNUMBER\":\"单据类型\"},\"FDate\":\"日期\",\"FStockOrgId\":{\"FNumber\":\"库存组织\"},\"FOwnerTypeIdHead\":\"BD_OwnerOrg\",\"FOwnerIdHead\":{\"FNumber\":\"货主\"},\"FNoteHead\":\"备注\",\"FBillEntry\":[明细]}}";
                metails = metails.Replace("单据编号", FBillNo);
                metails = metails.Replace("库存组织", StockOrgId);
                metails = metails.Replace("日期", FDate);
                metails = metails.Replace("单据类型", FBillTypeID);
                metails = metails.Replace("货主", OwnerIdHead);
                metails = metails.Replace("备注", FNoteHead);
                metails = metails.Replace("内码", FThirdSrcId);
                metails = metails.Replace("第三方分录", FThirdSrcBillNo);
                metails = metails.Replace("系统", FThirdSystem);
                //分录
                metails = metails.Replace("明细", entity_post_data);


                object saveres = WebApiServiceCall.Save(ctx, "STK_StockCountLoss", metails);
                JObject res = JObject.FromObject(saveres);
                JObject res1 = JObject.Parse(res["Result"].ToString());
                JObject res2 = JObject.Parse(res1["ResponseStatus"].ToString());
                result["Result"] = true;
                result["Message"] = res["Result"].ToString();
            }
            catch (Exception e)
            {
                result["Result"] = false;
                result["Message"] = "数据格式不正确！" + e.Message;
            }
            return result.ToString();
        }

        internal string RECEIVEBILL(Context ctx, string strParams, JObject result)
        {
            JObject jParams = JObject.Parse(strParams);
            string dataCenterID = CommonService.GetJParamString(jParams, "dataCenterID");
            string userName = CommonService.GetJParamString(jParams, "userName");
            string passWord = CommonService.GetJParamString(jParams, "passWord");
            string FBillNo = CommonService.GetJParamString(jParams, "FBillNo");
            if (string.IsNullOrWhiteSpace(FBillNo))
            {
                result["Result"] = false;
                result["Message"] = "单据编号不能为空！";
                return result.ToString();
            }
            string FSETTLETYPEID = "";
            string FRECTOTALAMOUNTFOR = "";
            string FCOMMENT = "";
            string FREALRECAMOUNTFOR_D = "";
            string FACCOUNTID = "";
            string FPURPOSEID = "";
            string FRECAMOUNTFOR_E = "";
            string FPOSTDATE = "";
            string FThirdSrcEntryId = "";
            string FStockOrgId = CommonService.GetJParamString(jParams, "FSETTLEORGID");
            string FSALEORGID = CommonService.GetJParamString(jParams, "FSALEORGID");
            string FDate = CommonService.GetJParamString(jParams, "FDATE");
            string FBillTypeID = CommonService.GetJParamString(jParams, "FBillTypeID");
            string FCONTACTUNITTYPE = CommonService.GetJParamString(jParams, "FCONTACTUNITTYPE");
            string FCONTACTUNIT = CommonService.GetJParamString(jParams, "FCONTACTUNIT");
            string FPAYUNITTYPE = CommonService.GetJParamString(jParams, "FPAYUNITTYPE");
            string FPAYUNIT = CommonService.GetJParamString(jParams, "FPAYUNIT");
            string FBUSINESSTYPE = CommonService.GetJParamString(jParams, "FBUSINESSTYPE");
            string FPAYORGID = CommonService.GetJParamString(jParams, "FPAYORGID");
            string FREMARK = CommonService.GetJParamString(jParams, "FREMARK");

            string FThirdSrcId = CommonService.GetJParamString(jParams, "FThirdSrcId");
            string FThirdSrcBillNo = CommonService.GetJParamString(jParams, "FThirdSrcBillNo");
            string FThirdSystem = CommonService.GetJParamString(jParams, "FThirdSystem");

            string StockOrgId = CommonService.VKGetBaseDataIdByValue(ctx, FStockOrgId);
            if (StockOrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FSETTLEORGID：编码】在系统中不存在！";
                return result.ToString();
            }
            string SALEORGID = CommonService.VKGetBaseDataIdByValue(ctx, FSALEORGID);
            if (SALEORGID == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FSALEORGID：编码】在系统中不存在！";
                return result.ToString();
            }
            string PAYORGID = CommonService.VKGetBaseDataIdByValue(ctx, FPAYORGID);
            if (PAYORGID == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FPAYORGID：编码】在系统中不存在！";
                return result.ToString();
            }
            string entity_post_data = "";
            string metails = "";
            try
            {
                List<string> entitys = new List<string>();
                //物料
                JArray FBillEntry = JArray.Parse(jParams["FRECEIVEBILLENTRY"].ToString());
                foreach (JObject List in FBillEntry)
                {
                    metails = "{\"FSETTLETYPEID\":{\"FNumber\":\"结算方式\"},\"FPURPOSEID\":{\"FNumber\":\"收款用途\"},\"FRECTOTALAMOUNTFOR\":表体-应收金额,\"FRECAMOUNTFOR_E\":收款金额,\"FACCOUNTID\":{\"FNumber\":\"我方银行账号\"},\"FCOMMENT\":\"备\",\"FRECAMOUNT_E\":收款金额,\"FPOSTDATE\":\"登账日期\",\"FNOTVERIFICATEAMOUNT\":表体-实收金额}";
                    FSETTLETYPEID = List["FSETTLETYPEID"].ToString();
                    FRECTOTALAMOUNTFOR = List["FRECTOTALAMOUNTFOR"].ToString();
                    FCOMMENT = List["FCOMMENT"].ToString();
                    FREALRECAMOUNTFOR_D = List["FREALRECAMOUNTFOR_D"].ToString();
                    FACCOUNTID = List["FACCOUNTID"].ToString();
                    FPURPOSEID = List["FPURPOSEID"].ToString();
                    FRECAMOUNTFOR_E = List["FRECAMOUNTFOR_E"].ToString();
                    FPOSTDATE = List["FPOSTDATE"].ToString();
                    FThirdSrcEntryId = List["FThirdSrcEntryId"].ToString();
                    //分录
                    if (string.IsNullOrWhiteSpace(FACCOUNTID))
                    {
                        FACCOUNTID = CommonService.VKBANKACNTByValue(ctx, PAYORGID);
                    }
                    if (FACCOUNTID == "null")
                    {
                        FACCOUNTID = CommonService.VKBANKACNTByValue(ctx, PAYORGID);
                    }
                    metails = metails.Replace("结算方式", FSETTLETYPEID);
                    metails = metails.Replace("表体-应收金额", FRECTOTALAMOUNTFOR);
                    metails = metails.Replace("备", FCOMMENT);
                    metails = metails.Replace("表体-实收金额", FREALRECAMOUNTFOR_D);
                    metails = metails.Replace("我方银行账号", FACCOUNTID);
                    metails = metails.Replace("收款用途", FPURPOSEID);
                    metails = metails.Replace("收款金额", FRECAMOUNTFOR_E);
                    metails = metails.Replace("登账日期", FPOSTDATE);
                    metails = metails.Replace("第三方源单分录编码", FThirdSrcEntryId);
                    entitys.Add(metails);
                }
                if (entitys.Count > 0)
                {
                    for (int j = 0; j < entitys.Count; j++)
                    {
                        entity_post_data = entity_post_data + entitys[j] + ",";
                    }
                }
                entity_post_data = entity_post_data.Remove(entity_post_data.Length - 1, 1);
                string metail = "{\"NeedUpDateFields\":[],\"NeedReturnFields\":[],\"IsDeleteEntry\":\"true\",\"SubSystemId\":\"\",\"IsVerifyBaseDataField\":\"false\",\"IsEntryBatchFill\":\"true\",\"ValidateFlag\":\"true\",\"NumberSearch\":\"true\",\"IsAutoAdjustField\":\"false\",\"InterationFlags\":\"\",\"IgnoreInterationFlag\":\"\",\"Model\":{\"FID\":0,\"FBillNo\":\"单据编号\",\"FBillTypeID\":{\"FNUMBER\":\"单据类型\"},\"FDATE\":\"业务日期\",\"FCONTACTUNITTYPE\":\"往来单位类型\",\"FCONTACTUNIT\":{\"FNumber\":\"往来单位\"},\"FPAYUNITTYPE\":\"付款单位类型\",\"FPAYUNIT\":{\"FNumber\":\"付款单位\"},\"FCURRENCYID\":{\"FNumber\":\"PRE001\"},\"FPAYORGID\":{\"FNumber\":\"收款组织\"},\"FSETTLERATE\":1.0,\"FSETTLEORGID\":{\"FNumber\":\"结算组织\"},\"FSALEORGID\":{\"FNumber\":\"销售组织\"},\"FDOCUMENTSTATUS\":\"Z\",\"FBUSINESSTYPE\":\"业务类型\",\"FISINIT\":false,\"FEXCHANGERATE\":1.0,\"FCancelStatus\":\"A\",\"FSETTLECUR\":{\"FNUMBER\":\"PRE001\"},\"FISB2C\":false,\"FIsWriteOff\":false,\"FREMARK\":\"备注\",\"FSETTLEMAINBOOKID\":{\"FNUMBER\":\"PRE001\"},\"FISCARRYRATE\":false,\"FRECEIVEBILLENTRY\":[明细]}}";
                metail = metail.Replace("单据编号", FBillNo);
                metail = metail.Replace("结算组织", StockOrgId);
                metail = metail.Replace("销售组织", SALEORGID);
                metail = metail.Replace("业务日期", FDate);
                metail = metail.Replace("单据类型", FBillTypeID);
                metail = metail.Replace("往来单位类型", FCONTACTUNITTYPE);
                FCONTACTUNIT = CommonService.VKFCustomerID(ctx, FCONTACTUNIT);
                metail = metail.Replace("往来单位", FCONTACTUNIT);
                metail = metail.Replace("付款单位类型", FPAYUNITTYPE);
                FPAYUNIT = CommonService.VKFCustomerID(ctx, FPAYUNIT);
                metail = metail.Replace("付款单位", FPAYUNIT);
                metail = metail.Replace("业务类型", FBUSINESSTYPE);
                metail = metail.Replace("收款组织", PAYORGID);
                metail = metail.Replace("备注", FREMARK);
                metail = metail.Replace("内码", FThirdSrcId);
                metail = metail.Replace("第三方分录", FThirdSrcBillNo);
                metail = metail.Replace("系统", FThirdSystem);
                metail = metail.Replace("明细", entity_post_data);

                object saveres = WebApiServiceCall.Save(ctx, "AR_RECEIVEBILL", metail);
                JObject res = JObject.FromObject(saveres);
                JObject res1 = JObject.Parse(res["Result"].ToString());
                JObject res2 = JObject.Parse(res1["ResponseStatus"].ToString());
                result["Result"] = true;
                result["Message"] = res["Result"].ToString();
            }
            catch (Exception e)
            {
                result["Result"] = false;
                result["Message"] = "数据格式不正确！" + e.Message;
            }
            return result.ToString();
        }

        internal string REFUNDBILL(Context ctx, string strParams, JObject result)
        {

            JObject jParams = JObject.Parse(strParams);
            string dataCenterID = CommonService.GetJParamString(jParams, "dataCenterID");
            string userName = CommonService.GetJParamString(jParams, "userName");
            string passWord = CommonService.GetJParamString(jParams, "passWord");
            string FBillNo = CommonService.GetJParamString(jParams, "FBillNo");
            if (string.IsNullOrWhiteSpace(FBillNo))
            {
                result["Result"] = false;
                result["Message"] = "单据编号不能为空！";
                return result.ToString();
            }
            string FSETTLETYPEID = "";
            string FREFUNDAMOUNTFOR = "";
            string FNOTE = "";
            string FREALREFUNDAMOUNTFOR_D = "";
            string FACCOUNTID = "";
            string FPURPOSEID = "";
            string FPOSTDATE = "";
            string FThirdSrcEntryId = "";
            string FStockOrgId = CommonService.GetJParamString(jParams, "FSETTLEORGID");
            string FSALEORGID = CommonService.GetJParamString(jParams, "FSALEORGID");
            string FDate = CommonService.GetJParamString(jParams, "FDATE");
            string FBillTypeID = CommonService.GetJParamString(jParams, "FBillTypeID");
            string FCONTACTUNITTYPE = CommonService.GetJParamString(jParams, "FCONTACTUNITTYPE");
            string FCONTACTUNIT = CommonService.GetJParamString(jParams, "FCONTACTUNIT");
            string FRECTUNITTYPE = CommonService.GetJParamString(jParams, "FRECTUNITTYPE");
            string FRECTUNIT = CommonService.GetJParamString(jParams, "FRECTUNIT");
            string FBUSINESSTYPE = CommonService.GetJParamString(jParams, "FBUSINESSTYPE");
            string FPAYORGID = CommonService.GetJParamString(jParams, "FPAYORGID");
            string FREMARK = CommonService.GetJParamString(jParams, "FREMARK");

            string FThirdSrcId = CommonService.GetJParamString(jParams, "FThirdSrcId");
            string FThirdSrcBillNo = CommonService.GetJParamString(jParams, "FThirdSrcBillNo");
            string FThirdSystem = CommonService.GetJParamString(jParams, "FThirdSystem");

            string StockOrgId = CommonService.VKGetBaseDataIdByValue(ctx, FStockOrgId);
            if (StockOrgId == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FSETTLEORGID：编码】在系统中不存在！";
                return result.ToString();
            }
            string SALEORGID = CommonService.VKGetBaseDataIdByValue(ctx, FSALEORGID);
            if (SALEORGID == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FSALEORGID：编码】在系统中不存在！";
                return result.ToString();
            }
            string PAYORGID = CommonService.VKGetBaseDataIdByValue(ctx, FPAYORGID);
            if (PAYORGID == "0")
            {
                result["Result"] = false;
                result["Message"] = "参数【FPAYORGID：编码】在系统中不存在！";
                return result.ToString();
            }
            string entity_post_data = "";
            string metails = "";
            try
            {
                List<string> entitys = new List<string>();
                //物料
                JArray FBillEntry = JArray.Parse(jParams["FREFUNDBILLENTRY"].ToString());
                foreach (JObject List in FBillEntry)
                {
                    metails = "{\"FSETTLETYPEID\":{\"FNumber\":\"结算方式\"},\"FPURPOSEID\":{\"FNumber\":\"收款用途\"},\"FREFUNDAMOUNTFOR\":表体-应退金额,\"FREFUNDAMOUNTFOR_E\":表体-应退金额,\"FACCOUNTID\":{\"FNumber\":\"我方银行账号\"},\"FNOTE\":\"备\",\"FREFUNDAMOUNT_E\":表体-实退金额,\"FPOSTDATE\":\"登账日期\",\"FISPOST\":true,\"FRuZhangType\":\"1\",\"FPayType\":\"A\",\"FNOTVERIFICATEAMOUNT\":表体-实退金额,\"FByAgentBank\":false,\"FOverseaPay\":false}";
                    FSETTLETYPEID = List["FSETTLETYPEID"].ToString();
                    FREFUNDAMOUNTFOR = List["FREFUNDAMOUNTFOR"].ToString();
                    FNOTE = List["FNOTE"].ToString();
                    FREALREFUNDAMOUNTFOR_D = List["FREALREFUNDAMOUNTFOR_D"].ToString();
                    FACCOUNTID = List["FACCOUNTID"].ToString();
                    FPURPOSEID = List["FPURPOSEID"].ToString();
                    FPOSTDATE = List["FPOSTDATE"].ToString();
                    FThirdSrcEntryId = List["FThirdSrcEntryId"].ToString();
                    //分录
                    if (string.IsNullOrWhiteSpace(FACCOUNTID))
                    {
                        FACCOUNTID = CommonService.VKBANKACNTByValue(ctx, PAYORGID);
                    }
                    if (FACCOUNTID == "null")
                    {
                        FACCOUNTID = CommonService.VKBANKACNTByValue(ctx, PAYORGID);
                    }
                    metails = metails.Replace("结算方式", FSETTLETYPEID);
                    metails = metails.Replace("表体-应退金额", FREFUNDAMOUNTFOR);
                    metails = metails.Replace("备", FNOTE);
                    metails = metails.Replace("表体-实退金额", FREALREFUNDAMOUNTFOR_D);
                    metails = metails.Replace("我方银行账号", FACCOUNTID);
                    metails = metails.Replace("收款用途", FPURPOSEID);
                    metails = metails.Replace("登账日期", FPOSTDATE);
                    metails = metails.Replace("第三方源单分录编码", FThirdSrcEntryId);
                    entitys.Add(metails);

                }
                if (entitys.Count > 0)
                {
                    for (int j = 0; j < entitys.Count; j++)
                    {
                        entity_post_data = entity_post_data + entitys[j] + ",";
                    }
                }
                entity_post_data = entity_post_data.Remove(entity_post_data.Length - 1, 1);
                string metail = "{\"NeedUpDateFields\":[],\"NeedReturnFields\":[],\"IsDeleteEntry\":\"true\",\"SubSystemId\":\"\",\"IsVerifyBaseDataField\":\"false\",\"IsEntryBatchFill\":\"true\",\"ValidateFlag\":\"true\",\"NumberSearch\":\"true\",\"IsAutoAdjustField\":\"false\",\"InterationFlags\":\"\",\"IgnoreInterationFlag\":\"\",\"Model\":{\"FID\":0,\"FBillNo\":\"单据编号\",\"FBillTypeID\":{\"FNUMBER\":\"单据类型\"},\"FDATE\":\"业务日期\",\"FCONTACTUNITTYPE\":\"往来单位类型\",\"FISINIT\":false,\"FCONTACTUNIT\":{\"FNumber\":\"往来单位\"},\"FSETTLERATE\":1.0,\"FDOCUMENTSTATUS\":\"Z\",\"FRECTUNITTYPE\":\"收款单位类型\",\"FRECTUNIT\":{\"FNumber\":\"收款单位\"},\"FCURRENCYID\":{\"FNumber\":\"PRE001\"},\"FSETTLEORGID\":{\"FNumber\":\"结算组织\"},\"FSALEORGID\":{\"FNumber\":\"销售组织\"},\"FBUSINESSTYPE\":\"业务类型\",\"FEXCHANGERATE\":1.0,\"FCancelStatus\":\"A\",\"FPAYORGID\":{\"FNumber\":\"收款组织\"},\"FISSAMEORG\":true,\"FSETTLECUR\":{\"FNUMBER\":\"PRE001\"},\"FISB2C\":false,\"FIsWriteOff\":false,\"FREMARK\":\"备注\",\"FBookingDate\":\"业务日期\",\"FISCARRYRATE\":false,\"FSETTLEMAINBOOKID\":{\"FNUMBER\":\"PRE001\"},\"FREFUNDBILLENTRY\":[明细]}}";
                metail = metail.Replace("单据编号", FBillNo);
                metail = metail.Replace("结算组织", StockOrgId);
                metail = metail.Replace("销售组织", SALEORGID);
                metail = metail.Replace("业务日期", FDate);
                metail = metail.Replace("单据类型", FBillTypeID);
                metail = metail.Replace("往来单位类型", FCONTACTUNITTYPE);
                FCONTACTUNIT = CommonService.VKFCustomerID(ctx, FCONTACTUNIT);
                metail = metail.Replace("往来单位", FCONTACTUNIT);
                metail = metail.Replace("收款单位类型", FRECTUNITTYPE);
                FRECTUNIT = CommonService.VKFCustomerID(ctx, FRECTUNIT);
                metail = metail.Replace("收款单位", FRECTUNIT);
                metail = metail.Replace("业务类型", FBUSINESSTYPE);
                metail = metail.Replace("收款组织", PAYORGID);
                metail = metail.Replace("备注", FREMARK);
                metail = metail.Replace("内码", FThirdSrcId);
                metail = metail.Replace("第三方分录", FThirdSrcBillNo);
                metail = metail.Replace("系统", FThirdSystem);
                metail = metail.Replace("明细", entity_post_data);


                object saveres = WebApiServiceCall.Save(ctx, "AR_REFUNDBILL", metail);
                JObject res = JObject.FromObject(saveres);
                JObject res1 = JObject.Parse(res["Result"].ToString());
                JObject res2 = JObject.Parse(res1["ResponseStatus"].ToString());
                result["Result"] = true;
                result["Message"] = res["Result"].ToString();
            }
            catch (Exception e)
            {
                result["Result"] = false;
                result["Message"] = "数据格式不正确！" + e.Message;
            }
            return result.ToString();
        }
    }
}
